Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a sh file which includes those lines:

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.

like image 912
lei liu Avatar asked Jul 01 '16 02:07

lei liu


People also ask

How do I stop GNOME Terminal from closing?

Super User answer: Create a profile in which the preference “Title and Command/When command exits” is set to “Hold the terminal open”. Invoke gnome-terminal with the --window-with-profile or --tab-with-profile option to specify the terminal name.

How do I keep terminal open?

You can also put a $SHELL in a new line at the end of your script. The window will stay open, no matter from where you open your shell script (e.g. cmd / powershell / etc).

How do I open terminal gnome from terminal?

To quickly open a Terminal window at any time, press Ctrl+Alt+T. A graphical GNOME Terminal window will pop right up.


1 Answers

Your command works fine but the gnome-terminal closes after the somecommand terminates, the reason being gnome-terminal not running the bash as it's default shell.

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

-e "bash -c ./somecommand;bash"\
like image 56
Inian Avatar answered Sep 20 '22 18:09

Inian