1

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
0

1 Answer 1

3

What 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .