This question already has an answer here:
If I create a cronjob as:
* * * * * /root/runfile
And I put the contents of
#!/bin/bash printenv >> /root/printenv
The contents that appear in
LANGUAGE=en_CA:en HOME=/root LOGNAME=root PATH=/usr/bin:/bin LANG=en_US.UTF-8 SHELL=/bin/sh PWD=/root
Note that it says "
SHELL=/bin/sh" however my script has a shebang as
#!/bin/bash. But printenv (env, set) are all reporting
/bin/sh as the shell.
However if I run those commands inside
runfile it successfully reports /bin/bash:
ps -p$$ -ocmd= >> /root/printenv OR readlink /proc/$$/exe >> /root/printenv
It proves I'm in an actual /bin/bash shell:
As I write this question, I'm realizing that perhaps the reason is that it's inheriting the previous SHELL environment variable, and that never changes which is why its contents are still from the cron calling process which is /bin/sh. That explanation is confirmed in the second linked question by Gilles.