Shell代码段-循环
【for】
#for1 resource="a b c" for res in $resource do cd $res && bash setup.sh done # for2,不推荐使用此方式,参考while3 # for shname in $(ls *.sh) # do # name=$(echo "$shname" | awk -F. '{print $1}') # echo $name # done #for3 for (( i=1;i<10;i++)) do echo $i done
【while】
#while1和for2类似,可以使用for2更直观、清晰 ls -d */ | while read directory do cd $directory || echo "cd failed." done #while2 i=1 while(($i < 100)) do i=$(($i + 1)) done #while3 ls -rl | while read filename; do echo $filename done