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