如何从与xargs的运行脚本提示用户 [英] how to prompt a user from a script run with xargs

查看:141
本文介绍了如何从与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 ,参数从文件而不是标准输入读取。你可以使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆