1

When I log in as root and enter some random non-existing command, it says:

root@localhost:~# asdf
-bash: asdf: command not found
root@localhost:~# 

But when I do the same thing as user rakinar2 it says:

rakinar2@localhost:~$ asdf
bash: asdf: command not found
rakinar2@localhost:~$ 

Now what are difference between -bash and bash?

Ar Rakin
  • 189

1 Answers1

5

Bash started with a dash - as the first character for the command name (argument #0) starts as a login shell. (So does a shell given the -l / --login switch.) That affects the startup files it reads.

See: 6.1 Invoking Bash and 6.2 Bash Startup Files in the manual.

ilkkachu
  • 138,973
  • @ArRakin, if a login or non-login shell is started depends on what starts it. I don't know how you logged in as root, but if you're using sudo, sudo -i would start a login shell. Terminal emulators and stuff like screen usually probably start non-login shells, unless you've configured them to start login shells... – ilkkachu Aug 07 '21 at 14:51
  • I've used sudo su to log in as root... – Ar Rakin Aug 07 '21 at 14:53
  • @ArRakin See also https://unix.stackexchange.com/questions/218169 – Kusalananda Aug 07 '21 at 16:09