我只发现如何等待用户输入。然而,我只是想暂停,这样我的while为真就不会使我的计算机崩溃。

我尝试暂停(1),但它说-bash:语法错误接近意外的令牌“1”。怎样才能做到呢?


当前回答

还有:

read -p "Press enter to continue"

其他回答

运行多个sleep和命令

sleep 5 && cd /var/www/html && git pull && sleep 3 && cd ..

这将在执行第一个脚本之前等待5秒,然后在再次更改目录之前再次休眠3秒。

read -r -p "Wait 5 seconds or press any key to continue immediately" -t 5 -n 1 -s

按下任意一个按钮后继续

有关更多信息,请参阅read manpage ref 1, ref 2

在Mac OSX上,睡眠不需要几分钟,只需要几秒钟。有两分钟的时间,

sleep 120

在脚本中,您可以在需要暂停的操作之间添加以下内容。这将使例程暂停5秒。

read -p "Pause Time 5 seconds" -t 5
read -p "Continuing in 5 Seconds...." -t 5
echo "Continuing ...."

还有:

read -p "Press enter to continue"