Bash脚本-自动填充答案 [英] Bash script - Auto fill answer

查看:360
本文介绍了Bash脚本-自动填充答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的bash脚本有几个问题,是否可以自动填写答案?

I have a bash script that has several questions, is it possible to automatically fill the answers ?

./script.sh install 

答案y 2 1 n n

我该如何在bash中做到这一点?

How can I do that in bash ?

是否只能通过第一个答案?

edit: is it possible to only pass the first answer ?

echo "y" | install 

让用户选择回答下一个问题吗?

and let the choice to the user to answer the next questions ?

推荐答案

我会通过

I would pass a here document to stdin:

./script.sh install <<EOF
y
2
1
n
n
EOF

如果只需要一行,也可以使用echo:

If you want it on one line, you can also use echo:

echo -e "y\n2\n1\nn\nn" | ./script.sh install

但是,我更喜欢这里的文档解决方案,因为它的恕我直言更具可读性.

However, I prefer the here document solution since it is IMHO more readable.

这篇关于Bash脚本-自动填充答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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