sta*_*bra 12 command-line gnome-terminal
手册页状态:
-e, --command=STRING
Execute the argument to this option inside the terminal.
-x, --execute
Execute the remainder of the command line inside the terminal.
Run Code Online (Sandbox Code Playgroud)
第二个例子中的“命令行”指的是什么?它的“剩余部分”是什么?您能否举例说明这两个选项的不同之处?或者它们基本相同?
Olo*_*rin 16
考虑:
gnome-terminal -x sleep 10m --version
gnome-terminal -e 'sleep 10m' --version
Run Code Online (Sandbox Code Playgroud)
在第一个示例中,后面的所有内容-x都用于要执行的命令。因此 GNOME 终端将sleep 10m --version作为命令运行。--version在这种情况下,它成为 GNOME 终端要运行的命令的一部分。
在第二个中,只有单个字符串参数 to-e用作命令,没有别的。所以--version这里实际上是 GNOME 终端的一个选项。
如果您想运行一系列命令,第一个可能更有用:
gnome-terminal -x bash -c 'command 1; command 2; ...'
Run Code Online (Sandbox Code Playgroud)
这很难用-e,因为整个命令需要是单个字符串,因此您必须引用整个内容。这反过来意味着您需要更加小心引号和变量扩展等:
gnome-terminal -e "bash -c 'command 1 $foo; command 2; ...'"
Run Code Online (Sandbox Code Playgroud)
在这里,$foo将被当前的shell 展开。
gnome-terminal -e 'bash -c "command 1 | awk '\''{print $NF}'\''"'
Run Code Online (Sandbox Code Playgroud)
使用'命令字符串中包含恼人的报价处理。