MacOS – Running Cron with an updated Bash version

cronmacos

Is there a way to get cron to run with an updated version of Bash that's been installed?

My OS came with Bash 3.x installed stock and I've upgraded it to 5.x with macports.

When I query bash --version from a terminal.app window the 5.x version is reported.

If I run the same query from within a cron job: * * * * * /temp/test_bash.sh >> /tmp/test_bash.log 2>&1 the 3.x version which came stock with the OS is reported.

MacOS 10.10.5

Best Answer

This should be easy to sort.

From your shell, examine the full path of the bash you prefer

which bash

Then edit your script in tmp to call the same path to bash (or your script has to source in the dot files, but it’s custom to just make each item in cron know the full proper path and not depend on startup and login files as that is much more light weight for cron)

I’ll end with one last link on good customs for cron environment being intentionally different than an interactive shell.