6

From the manual of xargs:

-L max-lines 

Use at most max-lines nonblank input lines per command line. Trailing blanks cause an input line to be logically continued on the next input line. Implies -x.

What does "Trailing blanks cause an input line to be logically continued on the next input line" mean? Can you show it by some examples? Thanks.

Originated from https://unix.stackexchange.com/a/448294/674

Tim
  • 101,790

1 Answers1

11

What the manual is saying is that, trailing spaces at the end of a line of input will cause xargs to treat it as though it were part of the following line - effectively escaping the newline. Consider the following command execution:

user@host~:$ (echo "line1"; echo "line2") | xargs -L 1 echo
line1
line2

Because of the -L 1 option, each line of input is processed separately, so we get two lines of output. Now compare this with the following example, where the first line of input contains a trailing space:

user@host~:$ (echo "line1 "; echo "line2") | xargs -L 1 echo
line1 line2

Notice that the two lines are treated as a single line of input by xargs.


It's also worth noting (per the comments) that the -L max-lines option is an XSI extension (cf. the xargs man page on the Open Group website). This is also referred to as an X/Open System Interfaces Extension - a supplementary specification to the Single UNIX Specification (SUS).

For more information regarding the differences between POSIX, SUS, and XSI, see the following post:

Or consult the section on conformance from the Base Definitions Volume of the Open Group Base Specifications.

igal
  • 9,886