parallel --shebang-warp for ::: works.

This commit is contained in:
Ole Tange 2012-11-22 12:10:45 +01:00
parent 45763bc601
commit 0b1896c368
3 changed files with 70 additions and 6 deletions

View file

@ -923,14 +923,27 @@ sub read_options {
# @ARGV without --options
# This must be done first as this may exec myself
if(defined $ARGV[0] and ($ARGV[0]=~/^--shebang / or
$ARGV[0]=~/^--shebang-wrap / or
$ARGV[0]=~/^--hashbang /)) {
# Program is called from #! line in script
$ARGV[0]=~s/^--shebang *//; # remove --shebang if it is set
$ARGV[0]=~s/^--hashbang *//; # remove --hashbang if it is set
# remove --shebang-wrap if it is set
$::opt_shebang_wrap = ($ARGV[0]=~s/^--shebang-?wrap *//);
# remove --shebang if it is set
$::opt_shebang = ($ARGV[0]=~s/^--shebang *//);
# remove --hashbang if it is set
$::opt_shebang .= ($ARGV[0]=~s/^--hashbang *//);
if($::opt_shebang) {
my $argfile = shell_quote_scalar(pop @ARGV);
# exec myself to split $ARGV[0] into separate fields
exec "$0 --skip-first-line -a $argfile @ARGV";
}
if($::opt_shebang_wrap) {
# exec myself to split $ARGV[0] into separate fields
my $parser = shell_quote_scalar(shift @ARGV);
my $scriptfile = shell_quote_scalar(shift @ARGV);
exec "$0 $parser $scriptfile ::: @ARGV";
}
}
Getopt::Long::Configure("bundling","pass_through");
# Check if there is a --profile to set @::opt_profile

View file

@ -0,0 +1,27 @@
#!/bin/bash
echo "### Test basic --shebang-wrap"
cat <<EOF > /tmp/test--shebang-wrap
#!/usr/local/bin/parallel --shebang-wrap /usr/bin/perl
print "Shebang from perl with args @ARGV\n";
EOF
chmod 755 /tmp/test--shebang-wrap
/tmp/test--shebang-wrap arg1 arg2
echo "### Same as"
parallel /usr/bin/perl /tmp/test--shebang-wrap ::: arg1 arg2
echo "### Test --shebang-wrap with parser options"
cat <<EOF > /tmp/test--shebang-wrap
#!/usr/local/bin/parallel --shebang-wrap /usr/bin/perl -p
print "Shebang from perl with args @ARGV\n";
EOF
chmod 755 /tmp/test--shebang-wrap
/tmp/test--shebang-wrap <(seq 2) <(seq 11 12)
echo "### Same as"
parallel /usr/bin/perl\ -p /tmp/test--shebang-wrap ::: <(seq 2) <(seq 11 12)

View file

@ -0,0 +1,24 @@
### Test basic --shebang-wrap
Shebang from perl with args arg1
Shebang from perl with args arg2
### Same as
Shebang from perl with args arg1
Shebang from perl with args arg2
### Test --shebang-wrap with parser options
Shebang from perl with args
1
Shebang from perl with args
2
Shebang from perl with args
11
Shebang from perl with args
12
### Same as
Shebang from perl with args
1
Shebang from perl with args
2
Shebang from perl with args
11
Shebang from perl with args
12