如何从与xargs的运行脚本提示用户 [英] how to prompt a user from a script run with xargs
问题描述
我使用的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 $ C $选项C>,参数从文件而不是标准输入读取。你可以使用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的运行脚本提示用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!