我在文件中有一个脚本bla.sh,它是可执行的。当我单击它时,将执行脚本并关闭窗口。我希望窗户一直开着。
类似于cmd /k** commandWindows 中的命令。
PS我不希望使用pause的,但我希望能够在执行脚本之后写多个命令。
Ste*_*zzo 99
放在$SHELL脚本的末尾:

一个小缺陷:由于gnome-terminal没有bash像 shell那样运行它,它会将它视为一个应用程序,并在您尝试关闭终端时显示有关它的警告:
There is still a process running in this terminal
Closing the terminal will kill it.
Run Code Online (Sandbox Code Playgroud)
我没有找到隐藏此警告的好方法。如果需要,您可以通过运行以下命令完全禁用它:
gconftool --set /apps/gnome-terminal/global/confirm_window_close --type boolean false
Run Code Online (Sandbox Code Playgroud)
如果您使用xterm而不是 gnome-terminal,则不会发生这种情况;它应该打扰你。
小智 16
使用 Gnome 终端
在命令字符串的末尾使用 gnome-terminal 附加 ;bash 并使用 -c 选项调用脚本有效。例如:
gnome-terminal -e "bash -c ~/script.sh;bash"
Run Code Online (Sandbox Code Playgroud)
这将执行以下操作:
您可以通过关闭窗口或在 bash 提示符下键入 exit 来退出 gnome-terminal 窗口。或者您可以根据要求键入更多命令。
jay*_*ode 11
如果您有权访问该脚本,还可以在末尾添加以下代码:
read
Run Code Online (Sandbox Code Playgroud)
该代码将在关闭之前等待输入,因此终端将保持打开状态,直到您按 Enter。
小智 9
将bash's--init-file选项与临时管道一起使用:
bash --init-file <(echo './<script_name>')
Run Code Online (Sandbox Code Playgroud)
前任:
bash --init-file <(echo './bla.sh')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
198009 次 |
| 最近记录: |