Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is there a dash in front of zsh (-zsh) if I echo $0 in zsh?

Tags:

shell

zsh

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?

like image 738
Walter Tross Avatar asked Feb 24 '20 14:02

Walter Tross


1 Answers

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.

like image 120
chepner Avatar answered Sep 29 '22 18:09

chepner