Bash:按y或n时自动反应
我开始学习shell脚本。 我正在使用Ubuntu和APT,例如,我将使用shell脚本安装apacheBash:按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 -
#!/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