Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash:按y或n时自动反应_Bash_Shell_Apt Get - Fatal编程技术网

Bash:按y或n时自动反应

Bash:按y或n时自动反应,bash,shell,apt-get,Bash,Shell,Apt Get,我开始学习shell脚本。 我正在使用Ubuntu和APT,例如,我将使用shell脚本安装apache #!/bin/bash sudo apt-get update sudo apt-get install apache2 每个人都在思考工作,但他们的提示是 “按y/n安装…” 我希望我的脚本自动按yes 谢谢您的帮助。使用 $ sudo apt-get install apache2 -y 您可以查看了解更多信息。使用 $ sudo apt-get install apache2 -

我开始学习shell脚本。 我正在使用Ubuntu和APT,例如,我将使用shell脚本安装apache

#!/bin/bash 
sudo apt-get update
sudo apt-get install apache2
每个人都在思考工作,但他们的提示是

“按y/n安装…”

我希望我的脚本自动按yes

谢谢您的帮助。

使用

$ sudo apt-get install apache2 -y
您可以查看了解更多信息。

使用

$ sudo apt-get install apache2 -y

您可以查看了解更多信息。

对于任何没有
-y
选项作为
apt-get
的命令,您可以使用
yes
命令:

yes | yourcmd
要提供其他输入:

yes nothanks | yourcmd
或输入之间有延迟:

while true; do echo "y"; sleep 1;done | yourcmd

对于没有
-y
选项作为
apt get
的任何命令,您可以使用
yes
命令:

yes | yourcmd
要提供其他输入:

yes nothanks | yourcmd
或输入之间有延迟:

while true; do echo "y"; sleep 1;done | yourcmd

sudo-apt-get-update-y
参见:参见:
man-apt-get
sudo-apt-get-y
参见:参见:
man-apt-get