Trying to install a .sh that will automate installation of .pkg

Solution 1:

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.