I was reading about bash interactive and on interactive logins and found that running bash with -l option will start it as login shell but after doing so, when I ran command echo $0 to verify, it still shows as non login shell.[root@localhost ~]# bash -l[root@localhost ~]# echo $0bashIt should show - as prefix to shell name. Please confirm if I am going wrong.
Why is $0 not -bash in an interactive login shell?
bash;shell
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_shellWill 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 bashIn 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-bashshopt -u login_shellThe 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.