I'm on ubuntu 12.04 and I use gnome terminal as my default terminal. I need to open another terminal from the command line. I know I can do this with gnome-terminal but I want to run a command that always opens the default terminal so that my script can run on other distros, even the ones not using gnome.

EDIT: I want a bash script that opens the terminal.

  • Please clarify your question with specifics. What type of script you are executing and on which shell (terminal) you want to run the scripts? Give us a usecase, like my shell script is this and I want to run it in csh or zsh or bash – Web-E Aug 16 '12 at 5:55

xterm is available by default on almost all Linux distributions if I remember correctly.

So you could run a command in it, depending on the shell that the script's written in with something like this, (the example is for a bash shell script)

xterm -e "sh script.sh"

It'll spawn a new shell window and execute your script.

  • Just to know there isn't a system variable or something like that that calls the default terminal on the system? – Topo Aug 16 '12 at 17:29
  • 4
    echo $TERM tells you the name, whereas $TERM launches it. Most of the time it's xterm :) – Nitin Venkatesh Aug 16 '12 at 18:03

According to the answer to this question How can I set default terminal used in Unity? I would script it as follows:

 eval "$(gsettings get org.gnome.desktop.default-applications.terminal exec)"

If you would like to start a program inside the terminal, there is also the property 'exec-arg' which specifies the argument needed to execute something in the terminal by that specific terminal. For example when you want to execute a 'tail -f /var/log/messages':

CMD='tail -f /var/log/messages'
eval "$(gsettings get org.gnome.desktop.default-applications.terminal exec) $(gsettings get org.gnome.desktop.default-applications.terminal exec exec-arg) \$CMD"

The 'eval' is used because 'gsettings' returns the command and the argument in single-quotes. This would then be a generic solution for all desktops running GNOME/Unity.


You might want to use either this key combination CTRL + SHIFT + T which opens another tab in the same terminal window, or you might want to use this one: CTRL + ALT + T which opens another terminal window (without closing the one you currently use.).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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