How to run a script without closing the terminal?
I have a script in file bla.sh
and it is executable. When I click on it, the script is executed and the window is closed. I'd like the window to stay open.
Something like command cmd /k** command
in Windows.
P.S. I don't want to use pause
, but I want to able to write more commands after the script was executed.
Solution 1:
Put $SHELL
at the end of your script:
A small flaw: since gnome-terminal
isn't running the bash
as it's shell, it will regard it as an application and display a warning about it when you try to close the terminal:
There is still a process running in this terminal
Closing the terminal will kill it.
I've found no nice way to hide this warning. If you want, you can disable it entirely by running:
gconftool --set /apps/gnome-terminal/global/confirm_window_close --type boolean false
This doesn't happen if you're using xterm
instead of gnome-terminal; should it bother you.
Solution 2:
Using Gnome Terminal
Using gnome-terminal appending ;bash at the end of the command string and calling the script with -c option works. For example:
gnome-terminal -e "bash -c ~/script.sh;bash"
This does the following:
- opens gnome-terminal
- executes the script script.sh
- shows the bash prompt after the script has finished.
You can exit the gnome-terminal window by closing the window or type exit at the bash prompt. Or you can type more commands as requested.
Solution 3:
If you have access to the script, you may also add the following code at the end:
read
That code will wait for an input before closing, so the terminal will stay open until you press Enter.