我使用的xargs来填充,我要停止脚本,等待用户输入的参数的脚本。是这样的:
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'但读被忽略。看来,第二个脚本正在试图获得它从管道输入过?我试过的xargs -p ,但没有更好的。
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.
推荐答案如果 -a 是给的xargs ,参数从文件而不是标准输入读取。你可以使用bash的进程替换的使用语法≤(...)来动态创建的文件的
If the option -a is given to xargs, 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.
xargs -a <( echo A B C ) bash -c 'for x in "$@"; do echo $x; read; done'请注意,这里 $ @ (在这种情况下,'A')错过了第一个参数。这是因为的bash -c 使A到 $ 1,0 (一般需脚本文件的名称),和 $ @ 为 $ 1 , $ 2 等... (在这种情况下,B和C)。
Note that here$@misses the first argument ('A' in this case). This is because bash -c puts 'A' into $0 (which normally takes the name of the script file), and $@ provides $1, $2 etc... (in this case 'B' and 'C').
更多推荐
如何从与xargs的运行脚本提示用户
发布评论