Standard input contains the space-separated words alpha beta gamma.
Pass them as command-line arguments to echo.
Which command sequence is appropriate?
xargs splits standard input into items and appends them as arguments to the specified command, unlike a simple stdin pipe.
Detailed explanation
printf 'alpha beta gamma' | echoIncorrect. echo does not read its standard input when no arguments are supplied.
echo < printf 'alpha beta gamma'Incorrect. This treats printf as a filename for input redirection.
printf 'alpha beta gamma' | tee echoIncorrect. tee writes to a file named echo rather than building echo arguments.
printf 'alpha beta gamma' | xargs echoCorrect. xargs echo constructs an echo invocation from the input items.
Try it yourself
An example you can run in a temporary verification environment.
printf 'alpha beta gamma' | xargs printf '<%s>\n'Expected result
<alpha>
<beta>
<gamma>Key points
- xargs converts stdin to argv
- A normal pipe connects stdin to stdin
- Quoted input needs care
Notes
- Environment: GNU findutils xargs / 標準入力
- Use temporary files and harmless commands for stream experiments.
- Shell redirection syntax and xargs behavior should be checked on the target shell implementation.
Foundation review
Place the operation
xargs can batch many input items into one invocation, unlike a simple one-line pipeline.
Check the side effect
Use harmless echo-like commands and count the resulting invocations.