Man pages state:

-e, --command=STRING
Execute the argument to this option inside the terminal.
-x, --execute
Execute the remainder of the command line inside the terminal.

What is the "command line" in the second example referring to? And what is its "remainder"? Could you please give an example where these two options differ? Or are they basically the same?



gnome-terminal -x sleep 10m --version
gnome-terminal -e 'sleep 10m' --version

In the first example, everything after -x is used for the command to be executed. So GNOME Terminal will run sleep 10m --version as the command. --version in this case becomes part of the command to be run by GNOME Terminal.

In the second, only the single string argument to -e is used as the command, nothing else. So --version here is actually an option to GNOME Terminal.

The first can be more useful if you want to run a chain of commands:

gnome-terminal -x bash -c 'command 1; command 2; ...'

This is difficult to do with -e, because the entire command needs to be a single string, so you'll have to quote the whole thing. This in turn means that you need to be more careful of quotes and variable expansion and such:

gnome-terminal -e "bash -c 'command 1 $foo; command 2; ...'"

Here, $foo will be expanded by the current shell.

gnome-terminal -e 'bash -c "command 1 | awk '\''{print $NF}'\''"' 

Using ' inside the command string involves annoying quote handling.

  • 5
    I see now. It seems the -x option was probably invented as a convenient way to avoid the problems with quotes. – stackzebra Sep 6 '18 at 9:32

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.