Bash config files

From JJBwiki

Jump to: navigation, search

You can leave comments and suggestions about this guide <a href="http://blog.johnjosephbachir.org/?p=244">here</a>.

When bash starts, it looks at various files depending on the context.

Here are the bash configuration files:

  • /etc/profile
  • .bash_profile
  • .bash_login
  • .profile
  • .bash_logout
  • .bashrc

And the different context within which bash is invoked:

Contents

[edit] Interactive Shell (Login)

[edit] When does this happen?

  • When logging in to a machine (what this means varies by platform... for example I'm not sure if OS X considers a machine booting as "logging in"... maybe when Terminal is first started? I'll have to experiment with this...).
  • When opening a new terminal window in your terminal program. This might be configurable... in OS X Terminal.app, you can specify how bash is invoked. By default it is invoked as a login shell, but you could have it invoked with the --noprofile option.
  • When SSHing into a machine
  • When invoking bash at the command line with the --login option

[edit] What does Bash do?

Bash executes /etc/profile, and then only the first file it finds, of the following three, in this order:

  1. .bash_profile
  2. .bash_login
  3. .profile

[edit] Interactive Shell (Non-Login)

[edit] When does this happen?

When invoking bash at the command line without the -login option.

[edit] What does Bash do?

Bash only executes .bashrc

[edit] Non-interactive shell

[edit] When does this happen?

When invoking Bash to run a script at the command line. example: $ bash myscript.sh

[edit] What does Bash do?

Bash looks for the variable BASH_ENV in the environment, expands its value if it appears there, and uses the expanded value as the name of a file to read and execute.

Personal tools