yes/no当我在服务器上运行两次时,有一个shell脚本它会多次询问几次100次.我yes每次都厌倦了打字.有没有办法运行该脚本只是将yes作为默认选项.以下是我的脚本!仅供参考,我无法编辑我的剧本.我可以用它来运行它./ittp-update.sh
#!/bin/bash
echo "Do you need to install the necessary compiling tools?"
select yn in "Yes" "No"; do
case $yn in
Yes ) sudo apt-get install tools; break;;
No ) <Here I want to skip to the next step. I originally left it
blank and removed the "done" command (after esac command)
to do this, but if I choose yes, it skips to the end
(where the next "done" command is and ends the script>
esac
echo "Do you need to eidt your configuration?"
select ny in "No" "Yes"; do
case $ny in
No ) <what do I put here to skip to the next tag
(labeled compile for example purposes); break;;
Yes )
esac
echo "You have 3 options with how you can edit you config file."
Run Code Online (Sandbox Code Playgroud)
....
如果您只需对所有内容回答"是",则可以使用
yes Yes | ./ittp-update.sh
Run Code Online (Sandbox Code Playgroud)
这是如何工作的:
yes打印你给它的字符串(或"y",如果你没有给它任何东西,因为这是在*nix程序中给出肯定答案的默认方式)在标准输出上重复,直到它收到SIGPIPE.|)将前面command(yes)的标准输出连接到以下命令(./ittp-update.sh)的标准输入../ittp-update.sh完成时,壳会自动发送SIGPIPE到通过配管连接到它(仅任何命令yes在这种情况下).SIGPIPE,yes退出.有关man yes更多信息,请参阅