This is probably something very silly, but I cannot find any answers anywhere. I've tried to setup a .bashrc.d
directory with scripts to source within .bashrc
, to make the process more organised. Instead of manually sourcing each script in .bashrc.d
, I'm sourcing them in this way:
if [ -d "$HOME/.bashrc.d" ]; then
find "$HOME/.bashrc.d/" -type f -name "*.sh" | sort | \
while read -r f; do
source "$f"
done
fi
However, source "$f"
seems to be running inside a subshell, because the command doesn't actually source any of the files. It executes them as I can see by the output of set -x
, but e.g. none of the variable exports carry to the original iteractive shell. I also know this is a problem with sourcing inside the while loop and not with sourcing from .bashrc
, since manually sourcing these files actually works (albeit it doesn't solve this issue). What is even happening and how do I fix this?
for f in "$HOME/.bashrc.d"/*.sh
should work. – Gordon Davisson Jan 02 '22 at 20:59