Bash sleep in milliseconds

大憨熊 提交于 2019-12-03 22:57:36

Make sure you're running your script in Bash, not /bin/sh. For example:

#!/usr/bin/env bash
sleep 0.1

In other words, try to specify the shell explicitly. Then run either by: ./foo.sh or bash foo.sh.

In case, sleep is an alias or a function, try replacing sleep with \sleep.

Some options:

read -p "Pause Time .5 seconds" -t 0.5

or

read -p "Continuing in 0.5 Seconds...." -t 0.5
echo "Continuing ...."

Bash was complaining about decimal values,

read: 0.5: invalid timeout specification

I came around with this solution which works great.

sleep_fraction() {
  /usr/bin/perl -e "select(undef, undef, undef, $1)"
}

sleep_fraction 0.01428
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!