bash - 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
停止正常工作,所以显然我缺少一些东西。
解决方案
-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
遵循--
:
command "argument with spaces"
--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"
推荐阅读
- r - pivot_wider 在同一行上组合信息
- curl - 爬网时避免沉洞/恶意域
- search - 具有不同分析器的多个字段的 Solr 默认搜索字段
- java - 使用 lambda java 查找最大值
- docker - docker容器无法在vm上连接到互联网
- flutter - 当时我尝试使用火焰引擎加载base64图像时出现以下错误。我用火焰:^0.27.0
- android - 单击按钮时没有任何动作
- javascript - 使用 $.get 从循环外的数组中丢失值
- java - 使用 @Spy 为扩展抽象类的 Groovy 类编写 Mockito 单元测试时出错
- jsp - 折线图 - CanvasJS 和 .jsp 文件