-1

I have this function that I've written:

function alert { 
    command='display alert '
    content="${1} message ${2}"
    concat=$command$content
    osascript -e "${concat}"
}

When executed like:

alert 'Title' 'Message'

I get the error message:

25:27: syntax error: A end of script can’t go after this “my”. (-2740)

Why is that the case?

For reference this command works perfectly:

osascript -e 'display alert "Title" message "Message"'
shoe
  • 952
  • 1
  • 20
  • 44

1 Answers1

1

You're not putting quotes around the message and title in content. So they're being treated as variable names by the OSAScript interpreter.

function alert { 
    command='display alert '
    content="\"${1}\" message \"${2}\""
    concat=$command$content
    osascript -e "${concat}"
}
Barmar
  • 741,623
  • 53
  • 500
  • 612