6

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?

Swair
  • 721
  • 1
  • 7
  • 10
  • 3
    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. –  Jul 06 '13 at 02:33

1 Answers1

7

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).

Chris Down
  • 125,559
  • 25
  • 270
  • 266
  • I swear i looked up the man page before posting. Missed this part :(. Thanks for the answer! – Swair Jul 05 '13 at 08:47