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.
xargs -I{} echo user={} enabledCorrect. -I{} replaces each token {} with the current input line.
xargs -0 echo user={} enabledIncorrect. -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.
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 / 標準入力
- 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
Replacement mode gives positional control but commonly changes batching behavior.
Check the side effect
Use a harmless command and inspect the generated argument order.