typeset -U path pathdirs=() for dir in $pathdirs; do if [ -d $dir ]; then path+=$dir fi done