2013-05-17 58 views
6

有一个快速的问题,如何回答是在bash脚本

想象,我有这样的代码:

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, 如何自动执行此操作?

或者可能有一种方法可以在默认情况下回答“是”吗?

+4

[是](http://linux.die.net/man/1/yes),有。 – hammar

回答

4

命令假设风暴提出问题 - 使用此文件 - 例如:

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可以是任何无意义的字符外壳不会解释。

+0

太棒了!有用! – Vor

5

有了适当命名yes

+1

例如是| command.sh –

3

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. 
+0

谢谢,这是一个不错的选择 – Vor

5

我不知道,但我建议尝试:

echo yes | ./storm-install/storm_install.sh all `hostname` $INSTALLDIR 
+0

真的有用,谢谢 –

4

如果你正在运行一个脚本,试试这个:

yes "yes" | bash script.sh 
2

我有一个脚本需要通过“是”几次,最后我们需要通过“版本号”才能部署到联结。 有什么建议吗?

0
(echo yes ; echo no; echo yes) | script.sh