xargs: restore correct behaviour of -n option

Since commit 1ff7002b1 (xargs: fix handling of quoted arguments, closes
11441) the -n option hasn't worked properly:

   $ echo 1 2 3 | xargs -n 1 echo
   1
   2

   3

   $

Because state is now remembered between calls to process_stdin() it's
necessary to update the state before any premature return.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Ron Yorston
2020-02-19 11:01:39 +00:00
committed by Denys Vlasenko
parent ed8af51b60
commit 1c462d47a0
2 changed files with 12 additions and 1 deletions

View File

@@ -315,6 +315,7 @@ static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf)
}
}
if (state == SPACE) { /* word's delimiter or EOF detected */
state = NORM;
if (q) {
bb_error_msg_and_die("unmatched %s quote",
q == '\'' ? "single" : "double");
@@ -335,7 +336,6 @@ static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf)
if (n_max_arg == 0) {
goto ret;
}
state = NORM;
}
if (p == buf) {
goto ret;