What is the Linux equivalent to DOS pause?

前端 未结 9 568
猫巷女王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 16:52

    This function works in both bash and zsh, and ensures I/O to the terminal:

    # Prompt for a keypress to continue. Customise prompt with $*
    function pause {
      >/dev/tty printf '%s' "${*:-Press any key to continue... }"
      [[ $ZSH_VERSION ]] && read -krs  # Use -u0 to read from STDIN
      [[ $BASH_VERSION ]] && 

    Put it in your .{ba,z}shrc for Great Justice!

提交回复
热议问题