If in bash I do (from the command line)
echo $0
the output is
bash
and similarly in other shells.
But if I do the same in zsh the output is
-zsh
Why is there that dash in front of zsh?
An old convention among shells is that if the shell is invoked using a name that starts with -
, it should initialize itself as a login shell. Your terminal emulator is following this convention when it executes zsh
for you.
You can observe this using the -l
flag to zsh
's built-in exec
(which adds a leading -
to the name of the command).
% ( exec bash -c 'echo $0')
bash
% ( exec -l bash -c 'echo $0')
-bash
The effect of the leading -
is generally equivalent to running the shell with the -l
option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With