if $recursive=1; then result=`find $targetdir -mindepth 1 -print` else result=`find $targetdir -mindepth 1 -maxdepth 1 -print` fi for line in $result do stat $line done #for line in $( if [ $recursive = "1" ]; then # find $targetdir -mindepth 1 -print #else # find $targetdir -mindepth 1 -maxdepth 1 -print #fi ); do # # ...whatever #done