bash 如何打开 gnome 终端以不断地使用 gnome-terminal 执行命令?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38135995/
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-09-18 14:51:01  来源:igfitidea点击:

how to open a gnome terminal to execute a command with gnome-terminal, constantly?

bashgnome-terminal

提问by lei liu

I have a sh file which includes those lines:

我有一个包含这些行的 sh 文件:

gnome-terminal\
  --tab\
    --title="ElasticSearch"\
    --working-directory="/home/username/program/bin"\
    -e "bash -c './somecommand'"\

when I run it, a gnome terminal will open and run a command for me. The problem is, when I press ctrl+c to stop the running command, the terminal closed. Is there a way to stop the running command and keep the terminal alive? Thanks in advance.

当我运行它时,一个 gnome 终端将打开并为我运行一个命令。问题是,当我按 ctrl+c 停止运行命令时,终端关闭。有没有办法停止运行命令并使终端保持活动状态?提前致谢。

回答by Inian

Your command works fine but the gnome-terminalcloses after the somecommandterminates, the reason being gnome-terminalnot running the bashas it's default shell.

您的命令工作正常,但在终止gnome-terminal后关闭somecommand,原因是gnome-terminal没有运行bash它,因为它是默认 shell。

To get the bash prompt($) after the command command completes, you need to trigger it back.

$在命令命令完成后获得 bash 提示 ( ),您需要将其触发回来。

-e "bash -c ./somecommand;bash"\

回答by kgreen

-ehas since been deprecated. Use gnome-terminal -- somecommandnow.

-e此后已被弃用。gnome-terminal -- somecommand现在使用。