Skip to content

Comment on Show HN: A fix for the .bash_profile .bashrc .profile madnessparent

Comments

Alternatively, just ensure sourcing .bash_profile is idempotent[1], then .bashrc can simply be

    if [ -n "$PS1" -a -r "$HOME/.bash_profile" ]; then
        . "$HOME/.bash_profile"
    fi
because, on all platforms, PS1 is non-empty on startup iff bash is interactive.

[1] E.g., assuming PATH starts out non-empty, this

    export PATH_DEFAULT PATH="<stuff>:${PATH_DEFAULT:=$PATH}:<other stuff>"
should work for PATH in bash much as
    if [ -z "$PATH_DEFAULT" ]; then
        export PATH_DEFAULT="$PATH"
    fi
    export PATH="<stuff>:$PATH_DEFAULT:<other stuff>"
works in most any Bourne-derived shell. Having the _DEFAULT variables around comes in handy for clean build environments, as well (e.g., I build Emacs.app once and distribute it to several Macs, so I don't want configure to pull in random dependencies that just happen to be installed in MacPorts on my build machine).
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.