3

This is one sample program in the GNU parallel documentation for executing via the shell script shebang.


#!/usr/bin/parallel  --shebang-wrap --colsep " " /bin/bash
echo Arguments: $@

The output for

./bash_echo.parl gracias 'buenos dias'

is

gracias
buenos 
dias

The above script does not handle command line arguments that are quoted and contain spaces. The arguments are expanded instead and treated as individual inputs.

How do I obtain the correct output as for the bash script below?

#!/usr/bin/env bash
for i in "$@"; do
  echo "$i"
done

This, obviously, handles quoted command line args.

Output:

gracias
buenos dias

I've tried using the option 'colseps' setting the separator to ' ' but that isn't the solution.

Linus Fernandes
  • 498
  • 5
  • 30

1 Answers1

2

You have found a bug: --shebang-wrap was never tested with spaces.

Possible fix:

diff --git a/src/parallel b/src/parallel
index 69adfdac..e7c0d930 100755
--- a/src/parallel
+++ b/src/parallel
@@ -3302,9 +3302,10 @@ sub read_options() {
                @options = shift @ARGV;
            }
            my $script = Q(shift @ARGV);
+           my @args = map{ Q($_) } @ARGV;
            # exec myself to split $ARGV[0] into separate fields
-           exec "$0 --_pipe-means-argfiles @options @parser $script ".
-               "::: @ARGV";
+            exec "$0 --_pipe-means-argfiles @options @parser $script ".
+                "::: @args";
        }
     }
     if($ARGV[0] =~ / --shebang(-?wrap)? /) {

It seems to fix your issue, but it may introduce others.

For updates: Follow https://savannah.gnu.org/bugs/index.php?63703

Ole Tange
  • 31,768
  • 5
  • 86
  • 104
  • Shouldn't your regression and sanity tests cover any such eventuality? – Linus Fernandes Jan 25 '23 at 16:21
  • @fernal73 Yes, and it will be covered by the tests when this is fixed. If the fix does not introduce other errors, it will be part of the test suite of version 20230222. – Ole Tange Jan 25 '23 at 18:36