Why does running echo $0
in the bash REPL only return the name of the bash executable, but in zsh return the absolute path to the zsh executable?
In bash:
Davids-MacBook-Pro:~ david$ echo $0
-bash
In zsh:
in ~
echo $0
/usr/local/bin/zsh
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityWhat you get in $0
depends on how the shell was invoked. If you start it with bash
, it'll be bash
. If you start it with /bin/bash
, it'll be /bin/bash
. Ditto for zsh
.
$ bash
$ echo $0
bash
$ exit
exit
$ /bin/bash
$ echo $0
/bin/bash
$ exit
exit
$ /bin/../bin/../bin/bash
$ echo $0
/bin/../bin/../bin/bash
$ exit
exit
$ zsh
$ echo $0
zsh
$ exit
$ /bin/zsh
$ echo $0
/bin/zsh
$ exit
$ /bin/../bin/../bin/zsh
$ echo $0
/bin/../bin/../bin/zsh
$ exit