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?

1 Answer 1

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.

3
  • @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... Commented Aug 7, 2021 at 14:51
  • I've used sudo su to log in as root... Commented Aug 7, 2021 at 14:53
  • @ArRakin See also unix.stackexchange.com/questions/218169 Commented Aug 7, 2021 at 16:09

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.