[英]How to answer yes in Bash Script
有一个简单的问题,
想象我有这个代码:
mkdir -p $INSTALLDIR
sudo apt-get install -y git clojure leiningen
git clone git://github.com/maltoe/storm-install.git
./storm-install/storm_install.sh all `hostname` $INSTALLDIR
这个脚本会问,你想安装额外的软件包,我想说yes
,如何自动完成?
或者可能有一种方法可以默认回答任何问题?
我不确定,但我建议尝试:
echo yes | ./storm-install/storm_install.sh all `hostname` $INSTALLDIR
用命令命名为yes
如果您正在运行脚本,请尝试以下操作:
yes "yes" | bash script.sh
假设风暴问问题 - 使用这里的文档 - 示例:
mkdir -p $INSTALLDIR
sudo apt-get install -y git clojure leiningen
git clone git://github.com/maltoe/storm-install.git
./storm-install/storm_install.sh all `hostname` $INSTALLDIR <<-EOF
yes
EOF
EOF可以是shell无法解释的任何无意义字符。
apt
也有--force-yes
选项,可能会有所帮助:
--force-yes
Force yes; This is a dangerous option that will cause apt to
continue without prompting if it is doing something potentially
harmful. It should not be used except in very special situations.
Using force-yes can potentially destroy your system! Configuration
Item: APT::Get::force-yes.
我有一个脚本需要多次传递“是”,最后我们需要传递“版本号”才能部署到nexus。 有什么建议么?
( echo yes ; echo no; echo yes ) | script.sh
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.