Linux 防止 Gnome 终端在执行后退出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4465930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 00:19:47  来源:igfitidea点击:

Prevent Gnome Terminal From Exiting After Execution

linuxbashterminalgnome-terminal

提问by Cerin

How do you prevent gnome-terminal from exiting after its given command has exited?

在给定的命令退出后,如何防止 gnome-terminal 退出?

I'm calling gnome-terminal from a cronjob, in order to create a terminal accessible to the user. The terminal is initially given a specific program to run. e.g.

我正在从 cronjob 调用 gnome-terminal,以创建一个可供用户访问的终端。终端最初被赋予一个特定的程序来运行。例如

gnome-terminal --tab -e "/usr/bin/myprog"

This works fine, except that when "myprog" exits, so does the gnome-terminal. How do I keep it running, but just drop back to a terminal prompt?

这工作正常,除了当“myprog”退出时,gnome-terminal 也会退出。我如何让它继续运行,但只是回到终端提示?

采纳答案by Paused until further notice.

Try this:

尝试这个:

gnome-terminal --tab -e "/bin/bash -c '/usr/bin/myprog; exec /bin/bash -i'"

回答by mob

Create a shell script like this:

像这样创建一个shell脚本:

#!/bin/bash
# myprog-wrapper.sh - runs /usr/bin/myprog and then starts a new bash session
/usr/bin/myprog
/bin/bash

Give the shell script execute permission.

授予 shell 脚本执行权限。

Then set up your cron job to call this script instead of directly calling myprog:

然后设置您的 cron 作业来调用此脚本,而不是直接调用myprog

gnome-terminal --tab -e "/path/to/myprog-wrapper.sh"

Replace /bin/bashwith your shell of choice.

替换/bin/bash为您选择的外壳。

回答by ak2

You could use xterm or rxvt-unicode instead of gnome-terminal, both of which have the -holdoption for this purpose.

您可以使用 xterm 或 rxvt-unicode 而不是 gnome-terminal,这两者都有-hold用于此目的的选项。

回答by Diego Torres Milano

alt text

替代文字

Create a profile (i.e. hold), set "When command exits: Hold the terminal open" and then

创建配置文件(即保持),设置“当命令退出时:保持终端打开”,然后

$ gnome-terminal --tab --profile hold -e /usr/bin/myprog