To have an -
as the first character of the command name is just one way to signal a login shell, there are other signals. In fact, the correct way to detect that the present shell is a login shell is to ask the shell itself.
In the bash manual:
A login shell is one whose first character of argument zero is a -, or one started with the --login option.
In bash:
shopt -p login_shell
Will print -u
if the shell is not login, and -s
if it is.
Lets test it:
$ ln -s $(which bash) ./-bash # make a local copy of bash
$ PATH=$PATH:. # Big security problem, don't use it.
$ -bash # start the local copy of bash
$ echo $0 # Its name start with an -
-bash
$ shopt -p login_shell # Is it a login shell?
shopt -s login_shell # Yes!, the answer is -s
$ exit # leave the login shell
$ PATH=${PATH%:.} # Remove the local pwd from the path.
$ rm ./-bash # Remove the local copy of bash
In fact, that $0 has a - doesn't have to mean that the shell is a login shell:
$ bash -c 'echo $0; shopt -p login_shell' -bash 1 2 3
-bash
shopt -u login_shell
The other way (from the manual) to get a login shell, is just ask for it:
$ bash --login # ask for a login shell
$ echo $0 # What is its name?
bash
$ shopt -p login_shell # Is it a login shell?
shopt -s login_shell # Yes, it is!
$ exit # leave the login shell.