0

I'm trying to develop a bash script for OSX which asks the user whether or not they want to perform an action. When they answer yes (y) I want it to display a notification using AppleScript which sort of works at the moment. However, I wish to embed a variable inside this AppleScript notification but I am unable to escape it. My code at the moment is

#! /bin/bash

DATE="$( date '+%d/%m/%Y %H:%M:%S' )"

while true; do
  read -p "Would you like to know the date? (y/n)" yn
  case $yn in
      [Yy]* ) osascript -e 'display notification "$DATE" with title "Todays date"'; break;;
      [Nn]* ) exit;;
      * ) echo "Please answer yes or no.";;
  esac
done

However when I run it, this is what I get:

enter image description here

Does anyone have any idea of how to modify my script in such as way that it will simply display the variable $DATE rather than the name of the variable?

Thank you in advance for any help, Kind regards,

Tom

4
  • You just do osascript -e 'display notification '"$DATE"' with title "Todays date"'
    – Inian
    Jun 27, 2018 at 13:48
  • @Inian I get the response "27:34: syntax error: A number can’t go after this number. (-2740)"
    – Tom
    Jun 27, 2018 at 13:53
  • I don't think its a problem with a shell variable anymore I guess
    – Inian
    Jun 27, 2018 at 13:54
  • Fixed now, adding "'"$DATE"'" works
    – Tom
    Jun 27, 2018 at 13:55

0

Browse other questions tagged or ask your own question.