OK, so source
runs the script in the current shell and .
separately, as detailed in running script with ". " and with "source " for example, but, specifically, in my .bashrc
file, I have:
[ -f ~/.bash_aliases ] && source ~/.bash_aliases
[ -f ~/.git-completion.bash ] && source ~/.git-completion.bash
[ -s ~/.autojump/etc/profile.d/autojump.sh ] && source ~/.autojump/etc/profile.d/autojump.sh
Can I replace this with:
[ -f ~/.bash_aliases ] && . ~/.bash_aliases
[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash
[ -s ~/.autojump/etc/profile.d/autojump.sh ] && . ~/.autojump/etc/profile.d/autojump.sh
Will that work on OS X – is that the "POSIX" issue?
I tried it and the above still seem to work on Ubuntu (so they actually work with both source
and .
, that is, they give me the desired functionality in the shell). Should I choose one over the other, or am I missing something?
FWIW, on OS X, I source my .bashrc
from my .bash_profile
.
Best Answer
This is POSIX's definition of
.dot
:Considering the above, you might as well just replace your
[ -f ./file ] && source ./file
with. ./file
altogether. If the file is not there the worst that will happen is you'll get a notice at login - which is probably information you'd want to have, I think.Of course if you'd rather keep the test you could do: