You are running bash. That's why the prompt looks weird. Bash and zsh both use the PS1
variable as the main setting for the prompt, but they have different escape sequences (backslash-character in bash, percent-character in zsh, and the second characters have different meanings).
Normally the PS1
variable should be set by the shell's initialization file (.bashrc
or .zshrc
) and not exported to the environment (since it only makes sense inside one given program), but many systems (including major Linux distributions) are poorly configured and export PS1
. MacOS correctly does not export PS1
out of the box as far as I can tell, but it seems that your own files do (or maybe a different version of macOS from the one I checked), and for some reason the system bashrc
on macOS specifically does not change PS1
if it's already set.
The SHELL
environment variable does not indicate what shell you are running. It indicates what shell you want to run. It tells programs that want to start a shell which shell to run. Just running another shell manually does not change $SHELL
.
If you see a shell prompt and you aren't sure what shell is running, you can check with ps
. In all Bourne-style shells (sh, ash, bash, ksh, zsh, …), $$
stands for the shell's process id, thus ps $$
tells you what program the current shell is. In fish you'd get an error that makes it obvious you're running fish because $$
is not valid there.
su - $USER -s /bin/bash
to login with bash and load all environment correctly. (you actually are usingbash
when runexec bash
) – Edgar Magallon Nov 12 '22 at 05:11echo "$SHELL"
doesn't tell you anything useful for purposes of this question --SHELL
isn't intended to represent the current shell; instead, it's documented to represent it's the user's preferred shell.declare -p BASH_VERSION
if you want to conclusively know if you're in bash; ignoreSHELL
, which is completely irrelevant. – Charles Duffy Nov 13 '22 at 15:16