How do I pause my shell script for a second before continuing?

后端 未结 10 1701
借酒劲吻你
借酒劲吻你 2020-11-30 16:26

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.

I tried pause(1)

相关标签:
10条回答
  • 2020-11-30 16:46

    use trap to pause and check command line (in color using tput) before running it

    trap 'tput setaf 1;tput bold;echo $BASH_COMMAND;read;tput init' DEBUG
    

    press any key to continue

    use with set -x to debug command line

    0 讨论(0)
  • 2020-11-30 16:47

    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:

    /bin/sleep 3
    

    4 seconds would look like this:

    /bin/sleep 4
    
    0 讨论(0)
  • 2020-11-30 16:47

    Run multiple sleeps and commands

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

    This will wait for 5 seconds before executing the first script, then will sleep again for 3 seconds before it changes directory again.

    0 讨论(0)
  • 2020-11-30 16:49

    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.

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