在继续之前,如何暂停我的Shell脚本一秒钟?

本文翻译自:How do I pause my shell script for a second before continuing?

I have only found how to wait for user input. 我只发现了如何等待用户输入。 However, I only want to pause so that my while true doesn't crash my computer. 但是,我只想暂停一下while true以便我的while true不会崩溃。

I tried pause(1) , but it says -bash: syntax error near unexpected token '1' . 我尝试了pause(1) ,但它显示-bash: syntax error near unexpected token '1' How can it be done? 怎么做到呢?


#1楼

参考:https://stackoom.com/question/1SiSE/在继续之前-如何暂停我的Shell脚本一秒钟


#2楼

In Python (question was originally tagged Python) you need to import the time module 在Python中(问题最初被标记为Python),您需要导入时间模块

import time
time.sleep(1)

or 要么

from time import sleep
sleep(1)

For shell script is is just 对于shell脚本来说只是

sleep 1

Which executes the sleep command. 执行sleep命令。 eg. 例如。 /bin/sleep


#3楼

Use the sleep command. 使用sleep命令。

Example: 例:

sleep .5 # Waits 0.5 second.
sleep 5  # Waits 5 seconds.
sleep 5s # Waits 5 seconds.
sleep 5m # Waits 5 minutes.
sleep 5h # Waits 5 hours.
sleep 5d # Waits 5 days.

One can also employ decimals when specifying a time unit; 在指定时间单位时,也可以使用小数。 eg sleep 1.5s 例如sleep 1.5s


#4楼

I realize that I'm a bit late with this, but you can also call sleep and pass the disired time in. For example, If I wanted to wait for 3 seconds I can do: 我意识到我对此有点迟了,但是您也可以致电sleep并传递所需的时间。例如,如果我想等待3秒钟,则可以执行以下操作:

/bin/sleep 3

4 seconds would look like this: 4秒将如下所示:

/bin/sleep 4

#5楼

然后呢:

read -p "Press enter to continue"

#6楼

Within the script you can add the following in between the actions you would like the pause. 在脚本内,您可以在要暂停的操作之间添加以下内容。 This will pause the routine for 5 seconds. 这将使例程暂停5秒钟。

read -p "Pause Time 5 seconds" -t 5
read -p "Continuing in 5 Seconds...." -t 5
echo "Continuing ...."
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值