diff --git a/bin/foamCleanPath b/bin/foamCleanPath index 77ada4b593..11287273e7 100755 --- a/bin/foamCleanPath +++ b/bin/foamCleanPath @@ -27,59 +27,88 @@ # foamCleanPath # # Description -# Usage: cleanPath path [wildcard] .. [wildcard] +# Usage: foamCleanPath path [wildcard] .. [wildcard] # # Prints its argument (which should be a ':' separated path) # without all # - duplicate elements # - non-accessible directories # - elements whose start matches a wildcard +# +# Note: +# - this routine will fail when directories have embedded spaces +# - false matches possible if a wildcard contains '.' (sed regex) #------------------------------------------------------------------------------ +if [ "$#" -lt 1 -o "$1" = "-h" -o "$1" = "-help" ] +then + cat <&2 +Usage: ${0##*/} path [wildcard] .. [wildcard] -if [ $# -eq 1 ]; then - dirList="$1" -elif [ $# -gt 1 ]; then - dirList="$1" - shift - while [ 1 -le $# ] ; do - wildCard=$1 - shift - dirList=`echo "$dirList" | sed -e "s@${wildCard}[^:]*:@@g"` - done -else - echo "Usage: $0 path [wildcard]" 1>&2 - echo "" 1>&2 - echo "Prints argument path with all entries matching " 1>&2 - echo "the wildcard removed." 1>&2 - exit 1 + Prints its argument (which should be a ':' separated list) cleansed from + - duplicate elements + - non-accessible directories + - elements whose start matches one of the wildcard(s) +USAGE + exit 1 fi +dirList="$1" +shift +##DEBUG echo "input>$dirList<" 1>&2 + +# preserve current IFS and split on whitespace oldIFS="$IFS" -IFS=':' +IFS=' ' -newDirList='' +# "wildcard1 ... wildcardN" may have been passed as a single parameter +set -- $* -for dir in $dirList +# strip out wildcards via sed +while [ "$#" -ge 1 ] do - - #- non existing - if [ ! -e "$dir" ]; then - continue - fi - - #- duplicate - dirListWithout=`echo ":${newDirList}:" | sed -e "s@:${dir}:@::@"` - if [ "$dirListWithout" != ":${newDirList}:" ]; then - continue - fi - - newDirList="$newDirList:$dir" + wildcard=$1 + shift + ##DEBUG echo "remove>$wildcard<" 1>&2 + dirList=`echo "$dirList" | sed -e "s@${wildcard}[^:]*:@@g"` done +# split on ':' (and on space as well to avoid any surprises) +IFS=': ' +set -- $dirList + +##DEBUG echo "intermediate>$dirList<" 1>&2 + +# rebuild the list from scratch +unset dirList +for dir +do + ##DEBUG echo "check>$dir<" 1>&2 + #- dirs must exist + if [ -e "$dir" ] + then + #- no duplicate dirs + duplicate=`echo " $dirList " | sed -ne "s@ $dir @DUP@p"` + + if [ ! "$duplicate" ] + then + dirList="$dirList $dir" + fi + fi +done + +# parse on whitespace +IFS=' ' +set -- $dirList + +# join on ':' +IFS=':' +dirList="$*" + +# restore IFS IFS="$oldIFS" -# Remove leading or trailing colons -echo "$newDirList" | sed -e 's@^:@@' -e 's@:$@@' +##DEBUG echo "output>$dirList<" 1>&2 +echo "$dirList" # ----------------------------------------------------------------------------- diff --git a/etc/bashrc b/etc/bashrc index 99f0d872a5..7e9a84e8d9 100644 --- a/etc/bashrc +++ b/etc/bashrc @@ -175,11 +175,12 @@ wildCards="$FOAM_INST_DIR $HOME/$WM_PROJECT/$USER" cleanPath=`$cleanProg "$PATH" "$wildCards"` && PATH="$cleanPath" #- Clean LD_LIBRARY_PATH -export LD_LIBRARY_PATH=`$cleanProg "$LD_LIBRARY_PATH" "$wildCards"` +cleanPath=`$cleanProg "$LD_LIBRARY_PATH" "$wildCards"` && LD_LIBRARY_PATH="$cleanPath" #- Clean MANPATH -export MANPATH=`$cleanProg "$MANPATH" "$wildCards"` +cleanPath=`$cleanProg "$MANPATH" "$wildCards"` && MANPATH="$cleanPath" +export PATH LD_LIBRARY_PATH MANPATH # Source project setup files # ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -208,14 +209,17 @@ SOURCE $WM_PROJECT_DIR/etc/apps/cint/bashrc cleanPath=`$cleanProg "$PATH"` && PATH="$cleanPath" #- Clean LD_LIBRARY_PATH -export LD_LIBRARY_PATH=`$cleanProg "$LD_LIBRARY_PATH"` +cleanPath=`$cleanProg "$LD_LIBRARY_PATH"` && LD_LIBRARY_PATH="$cleanPath" #- Clean MANPATH -export MANPATH=`$cleanProg "$MANPATH"` +cleanPath=`$cleanProg "$MANPATH"` && MANPATH="$cleanPath" + +export PATH LD_LIBRARY_PATH MANPATH #- Clean LD_PRELOAD if [ "$LD_PRELOAD" != "" ]; then - export LD_PRELOAD=`$cleanProg "$LD_PRELOAD"` + cleanPath=`$cleanProg "$LD_PRELOAD"` && LD_PRELOAD="$cleanPath" + export LD_PRELOAD fi