Skip to content

Commit f3af515

Browse files
authored
xargs: eof ignored (#594)
* Test cases: "perl xargs" and "perl xargs ls" * Text entered manually: 1 2 3 ^D * xargs correctly runs a program (echo or ls) on 1, 2 and 3, then incorrectly waits to read more data from stdin (end of file was not seen) * Checking eof() after each read indicates whether xargs should terminate (no more args will follow so the program should not loop) * Tweak usage string to clarify that "prog" is optional (echo is the default)
1 parent 1af7418 commit f3af515

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

bin/xargs

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ my $Program = basename($0);
3131
my %o;
3232
getopts('0tn:L:l:s:I:', \%o) or die <<USAGE;
3333
Usage:
34-
$Program [-0t] [-n num] [-L num] [-s size] [-I repl] prog [args]
34+
$Program [-0t] [-n num] [-L num] [-s size] [-I repl] [prog [args ...]]
3535
3636
-0 expect NUL characters as separators instead of spaces
3737
-t trace execution (prints commands to STDERR)
@@ -59,11 +59,12 @@ my @args = ();
5959
$o{I} ||= '{}' if exists $o{I};
6060
$o{l} = 1 if $o{I};
6161
my $sep = $o{'0'} ? '\0+' : '\s+';
62-
63-
while (1) {
62+
my $eof = 0;
63+
while (!$eof) {
6464
my $line = "";
6565
my $totlines = 0;
6666
while (<STDIN>) {
67+
$eof = eof;
6768
chomp;
6869
next unless (length && m/\S/);
6970
$line .= $_ if $o{I};

0 commit comments

Comments
 (0)