Bash sleep in milliseconds

后端 未结 3 1607
别那么骄傲
别那么骄傲 2020-12-15 03:07

I need a timer which will work with milliseconds. I tried to use sleep 0.1 command in a script, but I see this error message:

syntax error: invali

相关标签:
3条回答
  • 2020-12-15 03:58

    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
    
    0 讨论(0)
  • 2020-12-15 04:06

    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.

    0 讨论(0)
  • 2020-12-15 04:07

    Some options:

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

    or

    read -p "Continuing in 0.5 Seconds...." -t 0.5
    echo "Continuing ...."
    
    0 讨论(0)
提交回复
热议问题