Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
Can you modify the script? –  enzotib Jan 6 '11 at 17:57
    
yes, its my script. –  UAdapter Jan 6 '11 at 18:07

6 Answers 6

up vote 19 down vote accepted

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.

share|improve this answer
1  
it works great, thx. –  UAdapter Jan 6 '11 at 20:33
8  
You can use exec $SHELL instead of just $SHELL to make the warning go away without changing settings. –  Andrea Corbellini Jan 29 '13 at 10:54

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.

share|improve this answer

If you are using xterm use -hold.

share|improve this answer

Using xterm and appending ;bash at the end of the command string works. For example:

xterm -e "bash ~/script.sh;bash"

This does the following:

  1. opens xterm
  2. executes the script script.sh
  3. shows the bash prompt after the script has finished.

You can exit the xterm window by closing the window or type exit at the bash prompt. Or you can type more commands as requested.

share|improve this answer
xterm -e bash --rcfile bla.sh

This will run the script in a new window, and even give you control of the window after it is finished.

However the new window will not load ~/.bashrc as normal, since we ran bla.sh instead. This can be remedied by putting

. ~/.bashrc

at the top of bla.sh

share|improve this answer

You can't!

But you can try running it without a terminal window. Press Alt+F2 and type gksu and the command, if it requires root privileges, if it does not, then skip the gksu.

But I think that may not work for you because it's a script, not a GUI program, just try.

share|improve this answer
3  
its linux everything should be possible ;) –  UAdapter Jan 6 '11 at 20:34
4  
@UAdapter I don't know about everything, but this is certainly possible... –  Eliah Kagan Jan 29 '13 at 9:04

protected by Radu Rădeanu Sep 30 at 8:53

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.