3

This question already has an answer here:

Someone had spawned a while true loop in bash (logged in as root) on a server. It kept spawning processes, which fortunately exited but I needed to kill the parent. I came to know it was spawned directly from command line and not from a script, so I grepped for '-bash' and killed those processes owned by root. It worked fine.

When you do ps aux, In the command column different variants of bash show up.

/bin/bash
-bash
-bash
-bash
/bin/bash
bash
/bin/bash
/bin/bash
bash

etc..

What are the differences?

marked as duplicate by Gilles, jasonwryan, slm, Renan, bahamat Jul 6 '13 at 4:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    I don't think this is a duplicate. @swair is asking what the difference between -bash and /bin/bash is, not what the difference between a login shell and non-login shell is. The answer to this question is, "-bash denotes a login shell and /bin/bash denotes a non-login shell." The answer to the other question is a list of differences between login shells and non-login shells. – user26112 Jul 6 '13 at 2:33
5

The leading dash indicates a login shell, from man bash:

A login shell is one whose first character of argument zero is a -, or one started with the --login option.

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.

bash and /bin/bash are the same, they just were invoked differently (the former was not invoked using the full path).

  • I swear i looked up the man page before posting. Missed this part :(. Thanks for the answer! – Swair Jul 5 '13 at 8:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.