My goal is to run a script, where the shebang line causes bash to be used. Somehow running bash always runs zsh for me, even though I installed bash 5 using Homebrew and Mac (10.15) comes with bash 3.
I would still like zsh to be the default shell.
My goal is to run scripts with bash, and the shebang lines with bash give me zsh, as shown by the syntax that the script recognizes. The use of -c
below is just for ease of illustration (as compared to a file with shebang).
Here are my attempts to access bash and the content of /etc/shells
$ /usr/local/opt/bash/bin/bash -c "echo $SHELL"
/bin/zsh
$ whereis bash
/bin/bash
$ /bin/bash -c "echo $SHELL"
/bin/zsh
$ /bin/bash -c 'echo $SHELL'
/bin/zsh
$ /usr/local/bin/bash -c "echo $SHELL"
/bin/zsh
$ /usr/local/bin/bash -c 'echo $SHELL'
/bin/zsh
$ cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.
/usr/local/bin/bash
/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
$ /usr/bin/env bash -c "echo $SHELL"
/bin/zsh
$ /bin/bash -c "ps -p $$"
PID TTY TIME CMD
6775 9 ttys011 0:00.31 -zsh
$/usr/local/opt/bash/bin/bash -c "ps -p $$"
PID TTY TIME CMD
69799 ttys001 0:00.38 -zsh
$ /usr/local/bin/bash -c 'ps -p $$'
PID TTY TIME CMD
69985 ttys001 0:00.01 ps -p 69985
$ /bin/bash -c "echo $0"
-zsh
$ /usr/local/opt/bash/bin/bash -c "echo $0"
-zsh
Also, I created the following file and ran it directly
#!/usr/bin/env bash
# With /bin/bash on the shebang we get the same output
ps -p $$
echo $SHELL
echo $0
echo bash $BASH_VERSION
echo zsh $ZSH_VERSION
The result is:
$ ./bashtest.sh
PID TTY TIME CMD
70188 ttys000 0:00.00 /bin/bash ./bashtest.sh
/bin/zsh
./bashtest.sh
bash 3.2.57(1)-release
zsh