如何在 shell 脚本执行期间处理用户提示/用户干预 [英] How to handle user prompt/user intervention during shell script execution
问题描述
考虑询问用户输入是否继续的 shell 脚本[yY/nN] 和另一个脚本调用所有这些脚本.
我不想手动输入 Yy.
注意:用户输入不是脚本的参数,它会在脚本执行期间随时发生.
考虑 3 个 shell 脚本,即:a.sh, b.sh, c.sh
.
执行时,脚本提示:
Consider shell scripts which ask user's input to proceed or not[yY/nN] and
another script calls all these scripts.
I don't want to give Yy input manually.
Note: User input is not an argument to a script and it occurs anytime during script execution.
Consider 3 shell scripts viz: a.sh, b.sh, c.sh
.
On execution, scripts prompt:
"You want to Proceed[Y/y/N/n]?"
现在,Wrapper.sh
调用 a.sh, b.sh, c.sh
并在这些脚本时提供 Y/y 或 N/n 输入提示.
我无法将参数作为 a.sh "Y"
[ps: a.sh b.sh c.sh 不可执行且不可编辑]
RHEL无法安装任何第三方插件,所以只需要使用默认插件/命令即可.
Now, Wrapper.sh
calls a.sh, b.sh, c.sh
and also provides Y/y or N/n input as and when those scripts prompts.
I can not pass an argument as a.sh "Y"
[ps: a.sh b.sh c.sh are not executable and non-editable]
Can not install any third party plugins on RHEL, So need to use only default plugins/commands.
推荐答案
您可以尝试 expect
工具,该工具用于将输入自动提供给交互式程序.尝试从这样的事情开始:
You can try expect
tool which is used to feed input automatically to an interactive program. Try to begin with something like this:
#!/usr/bin/expect
set timeout 10
spawn "PATH_TO/a.sh"
expect "You want to Proceed"
send "y\r"
interact
这篇关于如何在 shell 脚本执行期间处理用户提示/用户干预的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!