In my old .bashrc, I had a short section as follows:
PATH2ADD_SCRIPTBIN="/home/foo/bar/scriptbin" PATH2ADD_PYTHONSTUFF="/home/foo/bar/pythonprojects" PATH2ADDLIST="$PATH2ADD_SCRIPTBIN $PATH2ADD_PYTHONSTUFF" for PATH2ADD in $PATH2ADDLIST; do if [ -z `echo $PATH | grep "$PATH2ADD"` ]; then export PATH=$PATH:$PATH2ADD echo "Added '$PATH2ADD' to the PATH." fi done And in Bash, this worked just as intended: it appended the paths I included in $PATH2ADDLIST if they were not already present in the path (I had to do this after realizing how huge my path was getting each time I was sourcing my .bashrc). The output (when the provided paths were not already present) was as follows:
Added '/home/foo/bar/scriptbin' to the PATH. Added '/home/foo/bar/pythonprojects' to the PATH. However, I recently switched over to the magical land of Zsh, and the exact same lines of text now produce this result:
Added '/home/foo/bar/scriptbin /home/foo/bar/pythonprojects' to the PATH. Now I'm pretty sure that this is because of some difference in how Zsh does parameter expansion, or that it has something to do with how Zsh changes the for loop, but I'm not really sure how to fix this.
Might anyone have some insight?
zshbreaks from the POSIX standard to prevent word-splitting on parameter expansions by default. You can re-enable that withsetopt SH_WORD_SPLIT.