-# $Id$
-#
# Path information is stored on separate lines in XXXdirs.
# We extract each directory exists and add it to the appropriate PATH.
#
# Location of the XXXdirs files.
-DIR=$HOME/.profile.d
+DIR="$HOME/.profile.d"
# Set one path to be the same as another.
function copypath() {
# Sanitise and export.
path="$(eval echo \$$oldpath)"
- [ -z "$path" ] || eval export $newpath="$path"
+ [ -z "$path" ] || eval "export $newpath='$path'"
unset path newpath oldpath
}
# Check the file exists.
[ -e "$DIR/$dirs" ] || return
+ # Set IFS to newline only so that we can read $(embedded shell commands).
+ JGD=$IFS
+ IFS='
+'
# Read them.
path=
- for dir in $(cat "$DIR/$dirs"); do
+ while read dir; do
dir=$(eval echo "$dir")
[ -d "$dir" ] || continue
path="$path:$dir"
- done
+ done < "$DIR/$dirs"
unset dir
+ # Restore IFS.
+ IFS=$JGD
+ unset JGD
+
# Sanitise path.
path=${path#:}
[ -z "$path" ] && return
# Export.
- eval export $newpath="$path"
+ eval "export $newpath='$path'"
unset path newpath dirs
}