For each input name alice and bob, run echo user=NAME enabled.
Insert each name at the NAME position.
Which GNU xargs form is appropriate?
xargs -I REPL replaces the token in its command template with each input item, allowing placement away from the argument end.
Detailed explanation
xargs echo user={} enabledIncorrect. Without -I, {} is literal and input is appended as trailing arguments.
Incorrect. Without -I, {} is literal and input is appended as trailing arguments.
xargs -I{} echo user={} enabledCorrect. -I{} replaces each token {} with the current input line.
Correct. -I{} replaces each token {} with the current input line.
xargs -0 echo user={} enabledIncorrect. -0 changes the delimiter but does not enable token replacement.
Incorrect. -0 changes the delimiter but does not enable token replacement.
xargs -n0 echo user={} enabledIncorrect. -n controls the maximum arguments per command and is not a replacement option.
Incorrect. -n controls the maximum arguments per command and is not a replacement option.
Try it yourself
An example you can run in a temporary verification environment.
printf 'alice\nbob\n' | xargs -I{} echo user={} enabledExpected result
user=alice enabled
user=bob enabledKey points
- -I selects a replacement token
- Usually one input line runs one command
- Items can be placed anywhere
Notes
- Environment: GNU findutils xargs / 標準入力
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.