xargs substition of more than one argument
I don't know of an xargs
option which will do that, but you can achieve something similar with an invocation of bash -c
:
$ echo -e "line 1\nline 2\nline 3" | xargs bash -c 'echo "${@}" DONE' _
line 1 line 2 line 3 DONE
Note that xargs
does not provide the lines as arguments, even if you specify -L
. You might want to use -d
to specify that new-line separates items (gnu xargs only, I believe). Contrast the following:
$ echo -e "line 1\nline 2\nline 3" |
xargs bash -c 'printf "<%s>\n" "${@}" DONE' _
<line>
<1>
<line>
<2>
<line>
<3>
<DONE>
$ echo -e "line 1\nline 2\nline 3" |
xargs -d\\n bash -c 'printf "<%s>\n" "${@}" DONE' _
<line 1>
<line 2>
<line 3>
<DONE>
Convert newlines into \nul
terminators, then use xargs -0
$ echo -ne 'line 1\nline 2\nline 3\n' | tr '\n' '\0' | xargs -0 -Ix echo x DONE
line 1 DONE
line 2 DONE
line 3 DONE