Prevent Gnome Terminal From Exiting After Execution
Solution 1
Try this:
gnome-terminal --tab -e "/bin/bash -c '/usr/bin/myprog; exec /bin/bash -i'"
Solution 2
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
Solution 3
Create a shell script like this:
#!/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.
Then set up your cron job to call this script instead of directly calling myprog
:
gnome-terminal --tab -e "/path/to/myprog-wrapper.sh"
Replace /bin/bash
with your shell of choice.
Solution 4
You could use xterm or rxvt-unicode instead of gnome-terminal, both of which have the -hold
option for this purpose.
Related videos on Youtube
Cerin
Updated on July 09, 2022Comments
-
Cerin almost 2 years
How do you prevent gnome-terminal from exiting after its given command has exited?
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.
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?
-
Aaron Altman over 13 yearsAnother discussion of the same issue: stackoverflow.com/questions/3512055/…
-
Cerin over 13 years@Ignacio, it's a common term. Google shows over 100k results for it...
-
Cerin over 13 years@Ignacio, the terms "shell" and "terminal" are generally synonymous. If your vocabulary or technical environment differs, fine. Sorry for the confusion.
-
-
Cerin over 13 yearsVery simplistic. Thanks.
-
Omar Tariq over 7 yearsThere should be some way to create a profile with
hold the terminal open
option set via command-line only. -
Diego Torres Milano over 7 yearsDepending on your gnome-terminal, you can use gconf or gsettings to set or get tha value of that property:
gconftool-2 -g /apps/gnome-terminal/profiles/Profile0/exit_action
-
jcanizales over 5 yearsFor me this keeps the terminal window open, but it doesn't accept any more commands.
-
Member2017 over 4 yearsAs of January 2020, the -e option in gnome-terminal still runs properly but throws out the following warning: << Option “-e” is deprecated and might be removed in a later version of gnome-terminal. Use “-- ” to terminate the options and put the command line to execute after it. >> Based on that information, I confirmed that you can run the following command without receiving any warning messages: <<gnome-terminal --tab -- "/bin/bash -c '/usr/bin/myprog; exec /bin/bash -i'">>
-
Agguro about 4 yearsJust what I need. Only the command today is a little bit changed. Just to update: gnome-terminal --tab -- /bin/bash -c '/usr/bin/nasm; exec /bin/bash -i'
-
Andrew almost 3 yearsHad to set execution permissions but then this worked well, thanks. Also,
gnome-terminal
wants us to use--
now instead of-e
.