Flat Earth Catalogue

2022-07-01

Bash dotfiles hard-won knowledge

Be advised that macOS is weird about starting new logins vs other interactive shells.

A Bash login (interactive) shell runs one of .bash_profile, .bash_login, or .profile (in descending order of preference). This should set environment variables, which will be inherited by shells it spawns. 

It should also source .bashrc which will not be run automatically (.profile should first test to see if it's running in Bash or some other shell):

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # source .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

A Bash interactive non-login shell runs .bashrc which should set functions and aliases.

A non-interactive shell runs none of the above. The default .bashrc begins by checking for interactivity to enforce this:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

Not sure if this is the only reason non-interactive shells don't run .bashrc or if there are others.


22:26

Powered by Blogger

 

(K) 2002-present. All rights reversed, except as noted.

Hard-won technical knowledge, old rants, and broken links from 10 years ago. I should not have to explain this in the 21st century, but no, I do not actually believe the world is flat.

Past
current