【发布时间】:2018-04-16 00:22:15
【问题描述】:
我想在 Mac 上使用 Google Chrome 从命令行打开 .html 和 .xml 文件。通常我只使用open 命令,但是对于.xml 文件,我注意到默认应用程序是XCode,所以我想使用-a 参数指定应用程序。
以下命令有效:
Kurts-MacBook-Pro:MacOS kurtpeek$ open -a "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" ~/Documents/Seattle/comparables.xml
在这里,我将Google Chrome 的路径(其中包含空格)括在引号中。为了以后更容易输入,我想在.bash_profile中定义一个环境变量$chrome包含这个路径,我做了如下:
export chrome="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
echo 命令会打印出来:
Kurts-MacBook-Pro:~ kurtpeek$ echo $chrome
/Applications/Google Chrome.app/Contents/MacOS/Google Chrome
但是,如果我尝试使用此环境变量重新运行 open -a 以指定应用程序,则会收到以下错误:
Kurts-MacBook-Pro:~ kurtpeek$ open -a $chrome Documents/Seattle/comparables.xml
The files /Users/kurtpeek/Chrome.app/Contents/MacOS/Google and /Users/kurtpeek/Chrome do not exist.
显然,在这种情况下,Bash shell 无法“识别”我在chrome 的定义中添加的引号。我怎样才能做到这一点?
【问题讨论】:
标签: bash macos google-chrome command-line