Opening a terminal other than xterm, running a command on it, and not closing the terminal after it successfully finished

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).


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:

  • Debian #648271: 11.8.3 "Packages providing a terminal emulator" says xterm passes -e option straight to exec
  • Debian #275409: -T does not work with the x-terminal-emulator provider
  • Gnome #701691: -e accepts only one term; all other terminal emulators accept more than one term