How to run xfce-terminal with different commands per tab and keep using the tabs after the commands have returned?

The -H/-hold option is to keep the terminal emulator Window open once the applications started in it (shell or other) has exited. In that state, nothing more can happen.

If you want to start a command as a job of an interactive shell in the xfce4-terminal terminal emulator and keep the shell running and use it interactively after the application has exited, with bash, you can make use of the $PROMPT_COMMAND environment variable, to have xfce-terminal start an interactive shell that starts the given command just before the first prompt.

xfce4-terminal \
  -T eclipse \
  --working-directory=/home/stefan/oximity \
  -e 'env PROMPT_COMMAND="unset PROMPT_COMMAND; /opt/eclipse/eclipse" bash' \
  \
  --tab -T arandr \
  --working-directory=/home/stefan/oximity \
  -e 'env PROMPT_COMMAND="unset PROMPT_COMMAND; arandr /home/stefan/.screenlayout/oximity.sh" bash' \
  \
  --tab -T bash \
  --working-directory=/home/stefan/oximity \
  ...

That way, the commands are jobs of that shell which means you can suspend them with Ctrl-Z and resume them later with fg/bg as if you had entered them at the prompt of that interactive shell.

That assumes though that you don't set the $PROMPT_COMMAND in your ~/.bashrc. Also note that the exit status of the command will not be available in $?.

To make it even more like the command was entered at the shell prompt you can even add it to the history list. Like:

xfce4-terminal -T /etc/motd -e 'env PROMPT_COMMAND="
  unset PROMPT_COMMAND
  history -s vi\ /etc/motd
  vi /etc/motd" bash'

That way, once you exit vi, you can press the Up key to recall that same vi command.

An easier way to write it:

PROMPT_COMMAND='unset PROMPT_COMMAND; history -s "$CMD"; eval "$CMD"' \
  xfce4-terminal --disable-server \
          -T /etc/motd -e 'env CMD="vi /etc/motd" bash' \
    --tab -T       top -e 'env CMD=top bash'

The:

xfce4-terminal -e 'sh -c "cmd; exec bash"'

solution as given in other answers works but has some drawbacks:

  1. If you press Ctrl-C while cmd is running, that kills the outer sh since there's only one process group for both sh and cmd.
  2. You can't use Ctrl-Z to suspend cmd
  3. Like in the $PROMPT_COMMAND approach, the exit status of the command will not be available in $?.

You can work around 1 above by doing:

xfce4-terminal -e 'sh -c "trap : INT; cmd; exec bash"'

Or:

xfce4-terminal -e 'sh -ic "cmd; exec bash"'

With that latter one, you'll also be able to suspend the process with Ctrl-Z, but you won't be able to use fg/bg on it. You'll be able to continue it in background though by doing a kill -s CONT on the pid of cmd.


As far as I understood your question, you want to run some processes in a terminal, being able to Ctrl+C them and, after that, keep the window open, with the shell.

If I am right, this could be accomplished with a command like this:

xfce4-terminal -e "bash -c 'COMMAND; exec bash'"