在shell osascript命令中在''之间插入变量?

问题描述 投票:0回答:2

我在外壳程序脚本中使用MacOS osascript command,并且尝试运行以下命令:

osascript

理想情况下,该命令将以APPNAME=$@ if pgrep -x "$APPNAME" > /dev/null # checking if app is open then echo "Closing..." osascript -e 'quit app $APPNAME' else echo "*** The app is not open" fi 作为有效解决方案的示例。但是,我似乎无法在''引号之间插入变量。

什么是解决方法?

bash macos shell applescript zsh
2个回答
1
投票

单引号的点(无论如何是点之一)是为了防止变量插值。听起来您真正想要的是将双引号括入字符串的方法。有很多方法可以做到这一点。常见的是:

osascript -e 'quit app "Calendar"'

-1
投票

尝试:

osascript -e "quit app \"$appname\""

或者,如果osascript -e 'quit app '"$APPNAME" 需要其他双引号,请尝试:

osascript
© www.soinside.com 2019 - 2024. All rights reserved.