How to run a script without closing the terminal?

Put $SHELL at the end of your script:

alt text

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.


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:

  1. opens gnome-terminal
  2. executes the script script.sh
  3. 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.


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.

Tags:

Command Line