DOS 的 pause 命令的 bash 等价物是什么?

th3*_*h3t 15 bash console

在继续之前,我需要在 shell 脚本上暂停以显示警告。例如,在 DOS 上它是这样的:

doit.bat:

[...]
echo 'Are you sure? Press Ctrl-C to abort, enter to continue.'
pause
[...]
Run Code Online (Sandbox Code Playgroud)

我怎样才能在 bash 上做到这一点?目前, sleep 命令似乎可以解决问题,并且足够简单,但并不完全是这个想法:

文件

[...]
echo 'Are you sure? Press Ctrl-C to abort.'
sleep 3
[...]
Run Code Online (Sandbox Code Playgroud)

Huc*_*kle 11

类似的东西

echo -n "prompt"  #'-n' means do not add \n to end of string
read              # No arg means dump next line of input
Run Code Online (Sandbox Code Playgroud)

  • 在 Bash 中,这可以缩写为 `read -p "prompt"`。可以使用 `help` 命令检索有关 shell 内置程序的更多详细信息,例如 `help read`。 (14认同)