Skip to content

Instantly share code, notes, and snippets.

@radavis
Created October 3, 2017 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radavis/237e6db7ba2aa5a70cef4100765ea678 to your computer and use it in GitHub Desktop.
Save radavis/237e6db7ba2aa5a70cef4100765ea678 to your computer and use it in GitHub Desktop.

Linux Environment Variables

Bash reads different configuration files depending on how the shell session is started.

Shell Sessions

  • login: A user was authenticated (via user/password).
  • non-login: A new shell session was created within an authenticated session. A user was not authenticated.
  • interactive: A shell session attached to a terminal session (foreground).
  • non-interactive: A shell session not attached to a terminal session (background).

Examples:

  • Signing into a machine using SSH: Interactive Login Shell Session
  • Running a script: Non-Interactive, Non-Login Shell Session

Login Shell Session

  • reads /etc/profile, first. then,
  • ~/.bash_profile
  • ~/.bash_login
  • ~/.profile

Non-Login Shell Session

  • /etc/bash.bashrc - system-specific configuration
  • ~/.bashrc - user-specific configuration (common location for setting ENV variables)

Non-Interactive Shell Session

  • Reads the config file defined by BASH_ENV.

System-wide Configuration

  • /etc/profile
  • /etc/bash.bashrc
  • /etc/environment - if using nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment