Bash在osascript命令中扩展变量

时间:2018-06-18 16:41:13

标签: bash

有人可以告诉我如何在以下内容中扩展变量,请:

MESSAGE="Public IP Address has changed"
osascript -e 'tell application (path to frontmost application as text) to display \ 
dialog "My message is ${MESSAGE} " buttons {"OK"} with icon stop'

1 个答案:

答案 0 :(得分:1)

单引号阻止了变量扩展:3.1.2.2 Single Quotes

MESSAGE="Public IP Address has changed"
osascript -e 'tell application (path to frontmost application as text) to display \ 
dialog "My message is '"$MESSAGE"' " buttons {"OK"} with icon stop'
# ....................^^........^^

我在那里使用shell字符串连接:

  • 单引号以关闭单引号字符串的第一部分
  • 在双引号内展开的变量,
  • 单引号打开单引号字符串的最后一部分。