如何提示用户在终端中按 Enter 退出,以免终端自动关闭?

Bel*_*ndu 3 command-line bash terminal shell-script

这是我的 Port.sh 文件

echo 'Give me a maximum of 5 seconds to run please.'
lsof -i | grep Xvnc | grep ESTABLISHED | grep $USER
lsof -i | grep $USER | grep Xvnc | grep -o -P '(?<=:).*(?=->)'
echo 'Brought to you by a cloudy and unlucky day.'
echo 'Press enter to exit'
Run Code Online (Sandbox Code Playgroud)

我想让终端在关闭前的最后一个回声之后等待用户按回车键。

脚本完成后,我的 ubuntu 桌面环境中的所有用户都将终端设置为关闭。

谁能告诉我我能做些什么来让终端等待用户按下回车键。

我用谷歌搜索过,没有任何相关的东西出现。

mad*_*eon 8

在脚本末尾添加:

read junk
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅Bash 手册

  • 你甚至不需要“垃圾”,“阅读”本身就足够了。 (4认同)
  • 来自 Bash 手册:_如果未提供名称,则将读取的行分配给变量 REPLY._ (2认同)