Padraic Boocock
Padraic Boocock

Reputation: 1

Bash expand variable inside osascript command

Can someone tell me how to make the variable expand in the following, please:

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'

Upvotes: 0

Views: 531

Answers (1)

glenn jackman
glenn jackman

Reputation: 246807

The single quotes are preventing variable expansion: 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'
# ....................^^........^^

I'm using shell string concatenation there:

  • a single quote to close the first part of the single quoted string,
  • the variable expanded within double quotes,
  • a single quote to open the last part of the single quoted string.

Upvotes: 1

Related Questions