在脚本中,我该如何暂停特定的时间间隔来执行两个命令之间的操作?

我想做类似以下的事情:
#!/bin/bash
command1
<pause for 30 seconds>
command2
exit

怎么做呢?
2个回答

你可以在终端中使用这个。
command1; sleep 30; command2

在你的脚本中:
#!/bin/bash
command1
sleep 30
command2
exit

睡眠时间的后缀:
- s 表示秒(默认值) - m 表示分钟 - h 表示小时 - d 表示天数

您可以使用read -t命令。例如:
read -p "Continuing in 5 seconds..." -t 5
echo "Continuing..."

在你的脚本中:
command1
read -p 'Pausing for 30 seconds' -t 30
command2

请注意,您可以按下 Enter 键来跳过超时时间。