Probably, this is a general unix question and therefore not restricted to macOS. I would like to output the output of my rsync command as a notification message. But I don't succeed in placing the variable correctly. If my code is like this:

RSYNC1="$(rsync --itemize-changes -avz -e ssh \
/Users/user/ server:/home/backup/ --delete)" && \
osascript -e 'display notification "${RSYNC1}" with title "Backup"'

then ${RSYNC1} is just printed literlly, and if I escape the quotes like this

osascript -e 'display notification \"${RSYNC1}\" with title "Backup"'

then this error is given:

> 21:22: syntax error: „given“, „in“, „of“, experssion, „with“,
> „without“, other parameter name, etc. expected, but unknown token
> found. (-2741)

What do I have to change?


You have to use double quotes to get variable expansion. To print literal double quotes inside double quotes you have to escape them:

osascript -e "display notification \"${RSYNC1}\" with title \"Backup\""

Alternatively, use single quotes when inside the double quotes:

osascript -e "display notification '${RSYNC1}' with title 'Backup'"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.