如何从与xargs的运行脚本提示用户

编程入门 行业动态 更新时间:2024-10-27 23:16:56
本文介绍了如何从与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的运行脚本提示用户

本文发布于:2023-11-24 08:22:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624461.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   提示   用户   xargs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!