I recently installed a few softwares and needed to add their bin/
directories to my PATH
. Nothing abnormal so far. But I decided to be smart about it, and rewrote a part of my .profile
so I didn't have to copy/paste the same few lines of codes over and over. Here was my idea:
# Create an array with directories to be added to PATH
declare -a addpath=("$HOME/bin" "$HOME/.cabal/bin" "/opt/vert.x/current/bin")
# Add directories recursively
for dir in "${addpath[@]}"; do
if [ -d "$dir" ]; then
PATH="$dir:$PATH"
fi
done
I thought this had worked well.. until I rebooted my PC and got locked out of my session when trying to log in. It took me a while to figure out that it was actually because of my .profile
; once I commented those lines out, I was able to log into my session without being bounced back.
My question is; what did I do wrong with these lines? Is there a syntax error? Is there an other/better way to do that? What happened?