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

2

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.

Ishmul answered 1/7, 2016 at 2:15 Comment(1)
See also #5437399Culminate
T
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"\
Tempo answered 1/7, 2016 at 5:44 Comment(2)
This doesn't work for me. If I kill said command with <kbd>CTRL</kbd> + <kbd>C</kbd>, then it closes the whole tab.Agler
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 trickHaymaker
D
13

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

Divaricate answered 22/7, 2019 at 10:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.