Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a terminal command I run from an application launcher. This works great, however sometimes the command fails, so I'd like for the terminal to stay open so I can see the results. How can I do this?

share|improve this question
Which terminal are you using, gnome-terminal? – invert Aug 31 '10 at 13:15
Yes, gnome terminal. – Eugene M Aug 31 '10 at 14:49
up vote 15 down vote accepted

Assuming your command is called mycommand, I'd change my launcher to run this:

gnome-terminal -e "mycommand|less"

If you want a more permanent, perhaps cleaner solution, open up gnome-terminal, go to Edit, Profile preferences and click the Title and Command tab. Change the "When command exits" option to "Hold the terminal open".

When you execute commands, it should now leave the terminal open when something runs.

Edit: If you don't really care about the terminal, you could just use xterm's hold flag:

xterm -e "mycommand" hold
share|improve this answer
To keep the default terminal 'when command exits' action, I suggest creating a new terminal profile, set it to stay open after a command exits, and pass gnome-terminal the --tab-with-profile=PROFILENAME option. You can have many profiles for different bahaviours this way :-) – invert Aug 31 '10 at 13:22
xterm -hold -e mycommand – Roger Pate Aug 31 '10 at 15:38

Your launcher is running a script right?

At the end of your script add

read -p "Press any key to exit > " -n1 junk

Then your script will wait until you choose to end it.

share|improve this answer
+1, and to show the prompt only if the command fails (returns a non-zero exit code) one could do command || read -n1 -p "Command failed. Press any key to exit..." – Jukka Matilainen Aug 31 '10 at 12:50

In your .desktop shortcut, use this

Exec=gnome-terminal -x bash -c "YOUR_SCRIPT; exec $SHELL"

After your script is finished, the Bash process will replace itself with a new invocation of itself.

If you need to pass quoted arguments to your script, you have to escape the quotes:

Exec=gnome-terminal -x bash -c "YOUR_SCRIPT \"arg with spaces\"; exec $SHELL"
share|improve this answer

A slightly different approach from the other answers: run your command and if that fails, then spawn a shell. This way you don't have to hold the terminal open (which doesn't distinguish between command success or failure), and you might find that shell particularly useful in failure. To close it, just use Ctrl-D (EOF), "exit", Alt-F4 (or whatever your window manager uses to close windows), etc.


[ $# -eq 0 ] && {
  echo "$(basename $0): no command" >&2
  exit 1
"$@" || {
  echo "failed: $?"
  exec $SHELL

Place this file somewhere, such as ~/bin, then use "success-or-shell your original command" in your launcher.

share|improve this answer

This answer gives the best answer I've seen so far to doing what you want. They recommend making a script with the commands to execute and use it with the --init-file parameter (bash specific, but you could probably do the same for csh/tcsh/zsh, etc):

#!/bin/bash --init-file
commands to run

... and execute it as:

xterm -e /path/to/script
# or
gnome-terminal -e /path/to/script
# or
the-terminal -e bash --init-file /path/to/script/with/no/shebang
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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