首页 > 解决方案 > Gnome-terminal:-e 和 -- 之间的区别?

问题描述

我正在尝试打开一个显示正在写入的文件的终端。进度百分比被写入文件,我希望用户看到它。

我发现的大多数打开新终端的解决方案都说要使用-e,但返回

# Option "-e" is deprecated and might be removed in a later version of gnome-terminal
# Use "-- " to terminate the options and put the command line to execute after it.

我已经看到有关此错误的讨论,但我仍然不确定两者之间的功能差异-e实际上--是什么。如果我只是交换它们,我运行的脚本就会-e停止正常工作,所以显然我缺少一些东西。

标签: bashgnome-terminal

解决方案


-e将接受一个必须被解析为 shell 命令的参数,但它可以在其他gnome-terminal参数之前。例如,

gnome-terminal -e 'command "argument with spaces"' --some-other-gnome-terminal-option

--本身不是一种选择;这是一个特殊的参数,表示选项的结束。后面的任何内容--都会被gnome-terminal自己的选项解析器忽略,并像普通参数一样对待。就像是

gnome-terminal -- 'command "argument with spaces"' --some-other-gnome-terminal-option

将提出 2 个额外的论点来gnome-terminal遵循--

  1. command "argument with spaces"
  2. --some-other-gnome-terminal-option

此外,您会收到一个错误,因为gnome-terminal会尝试运行一个名为 的命令command "argument with spaces",而不是一个名为 的命令command


在实践中,这意味着您不能简单地替换-e--并收工。相反,您将首先移至选项列表-e末尾:

gnome-terminal --some-other-gnome-terminal-option -e 'command "argument with spaces"' 

然后替换-e '...'-- .... 该命令及其每个参数现在是 的不同参数gnome-terminal,这消除了对整个引用层的需要。

gnome-terminal --some-other-gnome-terminal-option -- command "argument with spaces"

推荐阅读