OSX Snow Leopard – Differences Between /usr/bin/login and /usr/bin/bash

osx-snow-leopardposix

Terminal.app has the Shells open with setting with the Default login shell (/usr/bin/login) and Command (complete path) (which by default contains /usr/bin/bash as path) options.

Out of the box, the option I find selected is Default login shell (/usr/bin/login).

What is the difference between /usr/bin/login, and /usr/bin/bash? Which one should be choose as default shell?

Best Answer

A practical difference is in the way that the resulting shell environment reads its initial configuration settings.

/usr/bin/login forks a login shell. I think that it invokes the authentication process, but you may not see any visible authentication interaction if you're already logged in. And, of course, if your login shell is not bash, login will invoke it instead of bash.

bash is a shell that knows whether it was invoked as a login shell or not. A bash login shell reads .bash_profile or .bash_login or .profile -- only one, in that order of preference. A non-login shell will not read a .profile but will read from .bashrc. This is normal bash behavior under modern *nix platforms, but it can lead to difficult to detect weird behaviors if you don't understand what's going on.

For instance, you can open a "login" shell via Terminal, and get one set of environmental variables (say, from your .profile), then type "bash" and get a completely different set of variables (from the .bashrc, plus any variables that were exported, minus those which were not). In particular, PATH can get mangled with repeated or missing entries.

Related Question