What is the Linux equivalent to DOS pause?

前端 未结 9 559
猫巷女王i
猫巷女王i 2020-11-30 16:15

I have a Bash shell script in which I would like to pause execution until the user presses a key. In DOS, this is easily accomplished with the \"pause\" command. Is there a

9条回答
  •  日久生厌
    2020-11-30 17:04

    Yes to using read - and there are a couple of tweaks that make it most useful in both cron and in the terminal.

    Example:

    time rsync (options)
    read -n 120 -p "Press 'Enter' to continue..." ; echo " "
    

    The -n 120 makes the read statement time out after 2 minutes so it does not block in cron.

    In terminal it gives 2 minutes to see how long the rsync command took to execute.

    Then the subsequent echo is so the subsequent bash prompt will appear on the next line.

    Otherwise it will show on the same line directly after "continue..." when Enter is pressed in terminal.

提交回复
热议问题