4 ms·
I try to maintain a cross platform set of bash startup scripts but the biggest problem is that macOS and Linux don't follow the same rules. .bash_profile is on
by LeoPanthera 6y ago
I try to maintain a cross platform set of bash startup scripts but the biggest problem is that macOS and Linux don't follow the same rules.
.bash_profile is only supposed to run after logging into an interactive shell, and .bashrc is for every new shell.
But macOS runs .bash_profile every single time you open a new shell window, so you have to do some creative scripting to make it do what you want to do.
- Spivak 6y agoWhy not just guard your .bash_profile with something like if shopt -q login_shell; then ... and then just pretend it’s the Linux-y way?
- LeoPanthera 6y agoMy solution is that bash_profile simply runs bashrc, and bashrc starts with: if [ -n "$PS1" ]; then That seems to work fine everywhere.
- matheusmoreira 6y agoI agree, this is a much better solution. Multiple shell configuration files should be deprecated and replaced with this.
- funcDropShadow 6y agoremove the - in front of bash in the settings of Terminal.app. Then the terminal does not run a login shell but an interactive shell. You might have to add -i after bash for that.
- m463 6y agoI use OS=`uname -s` if [ "$OS" = "Darwin" ] then # all the mac stuff add_plist () { /usr/libexec/PlistBuddy -c 'Delete :'"$1" ~/.MacOSX/environment.plist >/dev/null /usr/libexec/PlistBuddy -c 'Add :'"$1"' string "'"$2"'"' ~/.MacOSX/environment.plist >/dev/null } if [ ~/.bashrc -nt ~/.MacOSX/environment.plist ] then mkdir -p ~/.MacOSX add_plist PATH "$PATH" add_plist HISTFILESIZE "$HISTFILESIZE" add_plist HISTSIZE "$HISTSIZE" add_plist HISTTIMEFORMAT "$HISTTIMEFORMAT" add_plist HISTCONTROL "$HISTCONTROL" add_plist PS1 "$PS1" fi fi