Shebang does not set SHELL in cron
The shebang is working and cron has nothing to do with that. When a file is executed, if that file's content begins with #!
, the kernel executes the file specified on the #!
line and passes it the original file as an argument.
Your problem is that you seem to believe that SHELL
in a shell script reflects the shell that is executing the script. This is not the case. In fact, in most contexts, SHELL
means the user's prefered interactive shell, it is meant for applications such as terminal emulator to decide which shell to execute. In cron, SHELL
is the variable that tells cron what program to use to run the crontab entries (the part of the lines after the time indications).
Shells do not set the SHELL
variable unless it is not set when they start.
The fact that SHELL
is /bin/sh
is very probably irrelevant. Your script has a #!/bin/bash
line, so it's executed by bash. If you want to convince yourself, add ps $$
in the script to make ps
show information about the shell executing the script.