Trying to install a .sh that will automate installation of .pkg As title, I'm trying to install a .sh file but I cannot get it to work. When I run sh or bash autopkginstall.sh

I get the following error;

/usr/local/bin/autopkginstall.sh: line 18: zmodload: command not found
/usr/local/bin/autopkginstall.sh: line 20: strftime: command not found
/usr/local/bin/autopkginstall.sh: autopkginstall.sh: line 119: syntax error: unexpected end of file


Below is the .sh that I'm trying to install. 

#!/bin/zsh
# Purpose: automatically install any pkg file put into a certain folder
#
# From: Tj Luo.ma
# Mail: luomat at gmail dot com
# Web:  http://RhymesWithDiploma.com
# Date: 2013-12-11

    # variable to refer to script name without path
NAME="$0:t:r"

    # directory to check for pkg or mpkg files
DIR="$HOME/Action/AutoInstallPKG"

    # where do you want files to be moved after they are installed
SUCCESS_MOVE_TO="$HOME/.Trash/"

zmodload zsh/datetime

TIME=$(strftime "%Y-%m-%d--%H.%M.%S" "$EPOCHSECONDS")

    # where do you want files to be moved if they FAIL to be installed
ERROR_MOVE_TO="$HOME/Desktop/"

    # log our output here
LOG="$HOME/Library/Logs/AutoInstallPKG.$TIME.log"

    # quick function to
log () {

    echo "$NAME: $@" | tee -a "$LOG"

    if (( $+commands[terminal-notifier] ))
    then

        # if terminal-notifier exists, use it

        terminal-notifier -group "$NAME" \
                -sender com.apple.installer \
                -subtitle "Click to show folder $DIR:t" \
                -title "$NAME via launchd" \
                -message "$@"
    fi
}

die () { log "FATAL ERROR: $@" ; exit 1 }

if [ ! -d "$DIR" ]
then
        die "DIR is not a directory: $DIR"
fi

[[ ! -d "$SUCCESS_MOVE_TO" ]] &amp;&amp; mkdir -p "$SUCCESS_MOVE_TO"

[[ ! -d "$ERROR_MOVE_TO" ]] &amp;&amp; mkdir -p "$ERROR_MOVE_TO"

cd "$DIR" || die "Failed to chdir to $DIR"

    # remove .DS_Store file if it exists, so it won't keep launching `launchd`
rm -f .DS_Store

command ls -1 | while read line
do

    EXT="$line:e"

    case "$EXT" in
        pkg|mpkg)
                    log "Installing $line"
                    sudo installer -verboseR -pkg "$line" -target / -lang en 2&gt;&amp;1 | tee -a "$LOG"

                    EXIT="$?"

                    if [ "$EXIT" = "0" ]
                    then
                            log "$line installed!"

                            command mv -n "$line" "$SUCCESS_MOVE_TO" ||\
                            command mv -n "$line" "$ERROR_MOVE_TO"

                    else
                            log "Failed to install $line"
                            command mv -n "$line" "$ERROR_MOVE_TO"
                    fi
        ;;

        *)
                    log "$line is not a pkg or mpkg file"
                    command mv -n "$line" "$ERROR_MOVE_TO"
        ;;
    esac
done

REBOOT=no

fgrep -q 'installer: The install recommends restarting now.' "$LOG" &amp;&amp; REBOOT=should

fgrep -q 'installer: The install requires restarting now.'   "$LOG" &amp;&amp; REBOOT=must

case "$REBOOT" in
    must)
            log "You MUST reboot to complete installation!"
    ;;

    should)
            log "You should reboot to complete installation!"
    ;;

    no)
            log "No reboot required"
    ;;

esac


exit
#
#EOF


I'm trying to follow TJLuoma's autopkginstall project.
The file's shebang #!/bin/zsh (first line in the file) means the file should be run with the zsh shell. Bash and sh have different syntaxes to zsh — you should use the zsh shell to run this file.

The shebang is used so that the file itself can specify shell that should execute the file. By specifying /usr/bin/env /path/to/file.sh in the launch agent's plist you force to run the file with the shell determined by the variable SHELL which usually is bash on macOS. Instead, just provide the file path, /path/to/file.sh and the shebang will cause zsh to be used automatically.