mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-12-22 04:37:53 +00:00
--shebang implemented. Unittest passes.
This commit is contained in:
parent
d502fec809
commit
16939a0fa6
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -4,7 +4,14 @@ config.h
|
|||
config.log
|
||||
config.status
|
||||
parallel-*.bz2*
|
||||
parallel-*.tar.gz
|
||||
stamp-h1
|
||||
actual-results
|
||||
tmp
|
||||
video
|
||||
src/parallel.1
|
||||
src/parallel.html
|
||||
src/sem.1
|
||||
src/sem.html
|
||||
src/sql.1
|
||||
src/sql.html
|
||||
|
|
|
@ -2,10 +2,17 @@ fex syntax for splitting fields
|
|||
http://www.semicomplete.com/projects/fex/
|
||||
sql :foo 'select * from bar' | parallel --fex '|{1,2}' do_stuff {2} {1}
|
||||
|
||||
Import sql
|
||||
|
||||
Example:
|
||||
sql :foo 'select * from bar' | parallel --colsep '\|' do_stuff {4} {1}
|
||||
|
||||
Virker shebang?
|
||||
#!/usr/bin/sql -t
|
||||
|
||||
GNU kræver:
|
||||
--version
|
||||
--help
|
||||
-h
|
||||
|
||||
|
||||
--autocolsep: Læs alle linjer.
|
||||
Prøv fastlængde: Find tegn, som står i alle linjer på de samme pladser. Risiko for falske pos
|
||||
|
|
46
src/parallel
46
src/parallel
|
@ -640,6 +640,12 @@ If the semaphore is not released within secs seconds, take it anyway.
|
|||
Implies B<--semaphore>.
|
||||
|
||||
|
||||
=item B<--skip-first-line>
|
||||
|
||||
Do not use the first line of input (used by GNU B<parallel> itself
|
||||
when called with B<--shebang>).
|
||||
|
||||
|
||||
=item B<-S> I<[ncpu/]sshlogin[,[ncpu/]sshlogin[,...]]>
|
||||
|
||||
=item B<--sshlogin> I<[ncpu/]sshlogin[,[ncpu/]sshlogin[,...]]>
|
||||
|
@ -841,6 +847,21 @@ Support for B<-X> with B<--sshlogin> is limited and may fail.
|
|||
Exit if the size (see the B<-s> option) is exceeded.
|
||||
|
||||
|
||||
=item B<--shebang>
|
||||
|
||||
=item B<-Y>
|
||||
|
||||
GNU B<Parallel> can be called as a shebang (#!) command as the first line of a script. Like this:
|
||||
|
||||
#!/usr/bin/parallel -Yr traceroute
|
||||
|
||||
foss.org.my
|
||||
debian.org
|
||||
freenetproject.org
|
||||
|
||||
For this to work B<--shebang> or B<-Y> must be set as the first option.
|
||||
|
||||
|
||||
=back
|
||||
|
||||
=head1 EXAMPLE: Working as xargs -n1. Argument appending
|
||||
|
@ -2191,6 +2212,17 @@ sub parse_options {
|
|||
$Global::arg_file_sep = "::::";
|
||||
$Global::trim = 'n';
|
||||
|
||||
# This must be done first as this may exec myself
|
||||
if(defined $ARGV[0] and ($ARGV[0]=~/^-Y/ or $ARGV[0]=~/^--shebang /)) {
|
||||
# Program is called from #! line in script
|
||||
$ARGV[0]=~s/^-Y //; # remove -Y if on its own
|
||||
$ARGV[0]=~s/^-Y/-/; # remove -Y if bundled with other options
|
||||
$ARGV[0]=~s/^--shebang //; # remove --shebang if it is set
|
||||
my $argfile = pop @ARGV;
|
||||
# exec myself to split @ARGV into separate fields
|
||||
exec "$0 --skip-first-line -a $argfile @ARGV";
|
||||
}
|
||||
|
||||
Getopt::Long::Configure ("bundling","require_order");
|
||||
# Add options from .parallel/config
|
||||
my $parallel_config = $ENV{'HOME'}."/.parallel/config";
|
||||
|
@ -2265,6 +2297,9 @@ sub parse_options {
|
|||
"fg" => \$::opt_fg,
|
||||
"bg" => \$::opt_bg,
|
||||
"wait" => \$::opt_wait,
|
||||
# Shebang #!/usr/bin/parallel -Yotheroptions
|
||||
"Y|shebang" => \$::opt_shebang,
|
||||
"skip-first-line" => \$::opt_skip_first_line,
|
||||
) || die_usage();
|
||||
$Global::debug = (defined $::opt_D);
|
||||
if(defined $::opt_m) { $Global::xargs = 1; }
|
||||
|
@ -2334,6 +2369,9 @@ sub parse_options {
|
|||
if($#::opt_a == 0) {
|
||||
# One -a => xargs compatibility
|
||||
$Global::argfile = open_or_exit($::opt_a[0]);
|
||||
if($::opt_skip_first_line) {
|
||||
<$Global::argfile>; # Read first line and forget it
|
||||
}
|
||||
} else {
|
||||
# Multiple -a => xapply style
|
||||
argfiles_xapply_style();
|
||||
|
@ -2489,6 +2527,9 @@ sub argfiles_xapply_style {
|
|||
my $in_fh = gensym;
|
||||
for (my $fileno = 0; $fileno <= $#::opt_a; $fileno++) {
|
||||
$in_fh = open_or_exit($::opt_a[$fileno]);
|
||||
if($::opt_skip_first_line and $fileno == 0) {
|
||||
<$in_fh>; # Read first line and forget it
|
||||
}
|
||||
for (my $lineno=0;
|
||||
$content[$fileno][$lineno] = get_arg($in_fh);
|
||||
$lineno++) {
|
||||
|
@ -4530,6 +4571,7 @@ sub unlock {
|
|||
}
|
||||
|
||||
# Keep perl -w happy
|
||||
$Private::control_path = $Semaphore::timeout =
|
||||
$Semaphore::wait = 0;
|
||||
|
||||
$Private::control_path = $Semaphore::timeout = $Semaphore::wait =
|
||||
$::opt_skip_first_line = $::opt_shebang = 0 ;
|
||||
|
||||
|
|
2
src/sql
2
src/sql
|
@ -593,7 +593,7 @@ sub Usage {
|
|||
print map{ "$_\n" } @_;
|
||||
print "\n";
|
||||
}
|
||||
print `cat $0 | pod2man | man -l -`;
|
||||
print "sql [-hnr] [--table-size] [--db-size] [-p pass-through] [-s string] dburl [command]\n";
|
||||
}
|
||||
|
||||
sub get_alias {
|
||||
|
|
23
unittest/tests-to-run/test31.sh
Normal file
23
unittest/tests-to-run/test31.sh
Normal file
|
@ -0,0 +1,23 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo '### Test of #! with file as input'
|
||||
cat >/tmp/shebang <<EOF
|
||||
#!/usr/local/bin/parallel -Yr echo
|
||||
A
|
||||
B
|
||||
C
|
||||
EOF
|
||||
chmod 755 /tmp/shebang
|
||||
/tmp/shebang
|
||||
|
||||
echo '### Test of #! with 2 files as input'
|
||||
cat >/tmp/shebang <<EOF
|
||||
#!/usr/local/bin/parallel -Yr -a /tmp/123 echo
|
||||
A
|
||||
B
|
||||
C
|
||||
EOF
|
||||
chmod 755 /tmp/shebang
|
||||
seq 1 3 >/tmp/123
|
||||
/tmp/shebang
|
||||
|
8
unittest/wanted-results/test31
Normal file
8
unittest/wanted-results/test31
Normal file
|
@ -0,0 +1,8 @@
|
|||
### Test of #! with file as input
|
||||
A
|
||||
B
|
||||
C
|
||||
### Test of #! with 2 files as input
|
||||
A 1
|
||||
B 2
|
||||
C 3
|
Loading…
Reference in a new issue