#!/usr/local/bin/perl -w eval 'exec /usr/local/bin/perl -w -S $0 ${1+"$@"}' if 0; # not running under some shell # # An xargs clone. # # Gurusamy Sarathy # use Getopt::Std; use Text::ParseWords; my %o; getopts('tn:l:s:I:', \%o) or die <) { chomp; $line .= $_ if $o{I}; $totlines++; push @args, grep defined, quotewords('\s+', 1, $_); last if $o{n} and @args >= $o{n}; last if $o{s} and length("@args") >= $o{s}; last if $o{l} and $totlines >= $o{l}; } my @run = @ARGV; if ($o{I}) { exit(0) unless length $line; for (@run) { s/\Q$o{I}\E/$line/g; } } elsif ($o{n}) { exit(0) unless @args; push @run, splice(@args, 0, $o{n}); } else { exit(0) unless @args; push @run, @args; @args = (); } if ($o{t}) { local $" = "', '"; warn "exec '@run'\n"; } system(@run) == 0 or exit($? >> 8); }