Bash And Exclusions in a List
Just a quick snippet on doing exclusions when you loop through a list.
DIRS=`ls -l --time-style="long-iso" $MYDIR | egrep '^d' | awk '{print $8}'` EXCLUDELIST="mail Mail" for EXCLUDE in $EXCLUDELIST do DIRS=`echo $DIRS | sed "s/\b$EXCLUDE\b//g"` done for DIR in $DIRS do echo ${DIR} : done
For some reason on Solaris sed had an issue with "\b" so I adjusted to sed "s/$EXCLUDE//g". Shown as follow:
#Linux: $ echo "d1 d2 d3" | sed "s/\bd2\b//g" d1 d3 # Solaris Fails: # echo "d1 d2 d3" | sed "s/\bd2\b//g" d1 d2 d3 # Solaris Works # echo "d1 d2 d3" | sed "s/d2//g" d1 d3