15

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.

lei liu
  • 2,735
  • 1
  • 16
  • 18
  • See also https://stackoverflow.com/questions/5436899/how-do-i-start-commands-in-new-terminals-in-bash-script – tripleee Feb 03 '23 at 08:28

2 Answers2

16

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"\
Inian
  • 80,270
  • 14
  • 142
  • 161
  • 1
    This doesn't work for me. If I kill said command with CTRL + C, then it closes the whole tab. – starbeamrainbowlabs Aug 17 '18 at 11:12
  • Space (or the lack of one) around that ; is important. If somecommand has arguments you may need to quote your command. for example -e "bash -c ipython --pylab;bash" does not work but -e "bash -c 'ipython -i --pylab myscript.py';bash" did the trick – SRD Nov 09 '18 at 19:30
13

-e has since been deprecated. Use gnome-terminal -- somecommand now.

kgreen
  • 518
  • 6
  • 13