![如何在 Bash 终端的打开命令中对连字符进行编码?](https://linux22.com/image/1448209/%E5%A6%82%E4%BD%95%E5%9C%A8%20Bash%20%E7%BB%88%E7%AB%AF%E7%9A%84%E6%89%93%E5%BC%80%E5%91%BD%E4%BB%A4%E4%B8%AD%E5%AF%B9%E8%BF%9E%E5%AD%97%E7%AC%A6%E8%BF%9B%E8%A1%8C%E7%BC%96%E7%A0%81%EF%BC%9F.png)
我正在尝试编写一个小脚本,在执行 svn diff 时启动 Beyond Compare。到目前为止,它一直运行正常:
open -a /Applications/Beyond\ Compare.app "$6" "$7"
为了获得完整的功能,我需要添加带有连字符(-,破折号,减号)的参数
open -a /Applications/Beyond\ Compare.app "$6" "$7" -title1="$3" -title2="$5" -readonly
但是当我这样做时,open 命令会将连字符解释为其自身的标志并退出:
open: invalid option -- i
usage: ...
我尝试“引用”整个命令或转义选项。我应该怎么做才能获得额外的功能?
答案1
请参阅打开的手册页:
--args
All remaining arguments are passed to the opened application in the argv parameter to
main(). These arguments are not opened or interpreted by the open tool.
因此,你的命令看起来应该是这样的:
open -a /Applications/Beyond\ Compare.app "$6" "$7" --args -title1="$3" -title2="$5" -readonly