how to create desktop notifications from the command line

one can generate alerts from shell scripts by running applescript code. the following code works on my mac running Sierra.

#!/bin/sh
#
# macalert - display a desktop notification on a mac using applescript
#
# usage:
#        macalert "this is the title" this is the message
#
# notes:
# 1. the title only needs to be quoted if it includes white space.
# 2. make sure all options are checked (or adjust to suit) in:
#      System Preferences -> Notifications -> Script Editor -> Alerts
# 3. all but the last line of this file is pretty much for documentation...
#
# sound file. other sound files are in
# $HOME/Library/Sounds and /System/Library/Sounds
sound="default"
# default title if the 1st command line argument is not supplied.
title=${1-Alert!}
# don't include provided title in message.
shift
# message is the rest of the command line arguments, or provide a default.
msg=${@-Hey there!}
# use applescript to display the notification
/usr/bin/osascript -e "display notification \"$msg\" with title \"$title\" sound name \"$sound\""