I have the following script in my Arch Linux box:

xterm -e "sudo pacman -Syu;bash"

This will fire up an xterm and run the command sudo pacman -Syu on it. Because of the ;bash part, it will not close the xterm window once the command is finished. This is a command for updating my system and I don't want it to close because I'd like to see the output.

Why this will not work with other terminals, and in particular with lxterminal and roxterm (the only others I tried)? The exact same command with lxterminal or roxterm instead of xterm will fire up the terminal and close it immediately after the command is executed.

  • Works fine with gnome-terminal for me. – muru Sep 17 '14 at 0:24
  • @muru thanks for the feedback. So it seems that it's a roxterm or lxterminal specific issue. – geo909 Sep 17 '14 at 0:31
  • 1
    I was too quick, turns out I don't have it working on gnome-terminal either. Could you try with: lxterminal -e 'bash -c "sudo pacman -Syu;bash"' ? – muru Sep 17 '14 at 0:34
  • Works fine in roxterm, too. – helcim Feb 14 '16 at 10:45

The essential problem is that the VTE-based terminals don't handle the command-line in the same way as xterm. That's beside the possible problems with the (unnecessary in this discussion) hold option.

The quotes in this command

xterm -e "sudo pacman -Syu;bash"

are the issue. That quoted string is a single token, passed to xterm as a single parameter.

With xterm, the tokens after -e are first tried as parameters for an execv call. Failing that, it tries something like "${SHELL:-sh}" -c "parameters" (runs your preferred shell to interpret parameters as a command line). konsole does one or the other (probably the first, since that was the original behavior of xterm, and most of konsole's design dates from the late 1990s). When xterm was modified for luit, the "failing that" alternative helped with passing parameters to luit.

The VTE-based terminals for a while tried doing one aspect in one command-line option and the other in another option (as I recall it, -e and -x, but swapping the roles of the two options and the subject of an interesting Debian bug report that I don't see at the moment). In the current version, trying

gnome-terminal -e "sudo pacman -Syu;bash"

fails because it only works with the original xterm-like behavior. And (keeping in mind that the other terminals use somewhat older versions of VTE), since the gnome-terminal's developers (who overlap with VTE developers...) dropped the -x option a while back, that option isn't available for the command. This works because it follows the original xterm model:

gnome-terminal -e "bash -c \"sudo pacman -Syu;bash\""

The -e option is partly addressed in Debian by a shell script, which attempts to provide a minimal set of options (including one for title). The Debian policy for this was based on xterm in the late 1990s, and has been a topic of discussion more than once.

Further reading:


Different emulators have different capabilities and protocols for the hold open feature. Some simply will not/can not do this. Others require the script to specify that the emulator remain open. I ran into this when writing a simple script for a program called HDSentinel. Here are the various solutions I can up with:

KDE (Konsole emulator)

konsole -hold -e sudo ./HDSentinel

(-hold is the parameter needed)

Enlightenment (Terminology emulator)

terminology --hold -e "sudo ./HDSentinel"

(--hold is the parameter needed)

XFCE (XFCE4 emulator)

xfce4-terminal -H -x "sudo ./HDSentinel"

(-H is the parameter needed;)

EDIT: -x is used instead of -e in xfce terminal

Mate (mate-terminal emulator)

mate-terminal --window-with-profile=HoldOpen -e "sudo ./HDSentinel"

(with this emulator you must first create a custom profile to hold the emulator open, I called mine HoldOpen, but any name will do)

Gnome (gnome-terminal emulator)

gnome-terminal --window-with-profile=HoldOpen -e "sudo ./HDSentinel"

(works the same as Mate, create profile to hold emulator open)

LXDE (lxterminal)

The lxterminal emulator that comes with LXDE does not support holding the terminal open

So the bottom line is some emulators will support hold open, and some will not. Of those that do, how you enable that feature will vary. If you are looking at an emulator not listed here, you'll have to google the emulator to find out if/how you enable hold open.

If the emulator you have does not support hold open at all, you may find your distro does include an alternate emulator that does support it (many distros include xterm as well as their desktop version emulator). If you do not have an emulator that supports hold open, you can always got get one from the software repository.

This info represents quite a bit of research time, so I hope this will help folks save some time and frustration. BTW, xterm also uses the -hold parameter, so I believe that ;bash will serve to hold open an emulator that offers a parameter for the hold open feature. But that it will not create a hold open feature if the emulator does not support this (as in the case of lxterminal) or enable hold open if that emulator uses a custom profile to enable hold open (as in the case of Gnome).

  • Little did I expect I'd get such a thorough answer when I was asking this question; thank you, sir. – geo909 Sep 19 '14 at 0:10
  • That said.. @muru 's suggestion was correct. That is, lxterminal -e 'bash -c "sudo pacman -Syu;bash"' keeps lxterminal open.. – geo909 Sep 19 '14 at 0:14
  • @geo909 to be fair, I have no idea why it works. :) – muru Sep 19 '14 at 0:17
  • with regards to the mate-terminal, can you not just click on 'edit' -> 'profile preferences' and set the default profile to 'hold open after exit'? – john ktejik Sep 4 '15 at 3:06
  • This doesn't actually answer the question, which was "why this will not work with other terminals". For instance, -hold (implemented in xterm first...) is not needed, but the answer implies that konsole needs it (without answering why). In any case, the question was about the VTE-based terminals (so only 3 terminal types are mentioned). – Thomas Dickey Jan 18 '17 at 23:25

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.