I’m using xargs to populate the arguments to a script in which I want to stop the script, waiting for user input. Something like:
echo a b c | xargs bash -c 'for a in "$@"; do echo $a; read; done'
but the read gets ignored. It seems that the second script is trying to get it’s input from the pipe too? I’ve tried xargs -p but it’s no better.
If the option
-ais given toxargs, the arguments will be read from a file instead of stdin. You can use bash’s process substitution with the syntax<( ... )to create the file on the fly.Note that here
$@misses the first argument (‘A’ in this case). This is becausebash -cputs ‘A’ into$0(which normally takes the name of the script file), and$@provides$1,$2etc… (in this case ‘B’ and ‘C’).