gnome-terminal的-e和-x选项有什么区别?

时间:2023-02-14 06:54:17

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?

第二个例子中的“命令行”是指什么?它的“剩余部分”是什么?你能举个例子说明这两个选项有什么不同吗?或者它们基本相同?

1 个解决方案

#1


13  

Consider:

考虑:

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.

在第一个示例中,-x之后的所有内容都用于执行命令。所以GNOME终端将运行sleep 10m --version作为命令。在这种情况下,--version将成为GNOME终端运行命令的一部分。

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.

在第二个中,只有-e的单个字符串参数用作命令,没有别的。所以--version在这里实际上是GNOME终端的一个选项。

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:

这很难用-e,因为整个命令需要是一个单独的字符串,所以你必须引用整个事情。这反过来意味着您需要更加小心引号和变量扩展,例如:

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

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

这里,$ foo将被当前的shell扩展。

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

Using ' inside the command string involves annoying quote handling.

在命令字符串中使用'涉及恼人的报价处理。

#1


13  

Consider:

考虑:

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.

在第一个示例中,-x之后的所有内容都用于执行命令。所以GNOME终端将运行sleep 10m --version作为命令。在这种情况下,--version将成为GNOME终端运行命令的一部分。

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.

在第二个中,只有-e的单个字符串参数用作命令,没有别的。所以--version在这里实际上是GNOME终端的一个选项。

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:

这很难用-e,因为整个命令需要是一个单独的字符串,所以你必须引用整个事情。这反过来意味着您需要更加小心引号和变量扩展,例如:

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

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

这里,$ foo将被当前的shell扩展。

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

Using ' inside the command string involves annoying quote handling.

在命令字符串中使用'涉及恼人的报价处理。