今天對Script中的循環進行練習,而後使用一些script的調試參數oop
whilethis
#while while [ "$yn" != "yes" -a "$yn" != "YES" ] do read -p "Please input YES/yes to stop this program:" yn done echo "OK! you input the correct answer"
untilspa
#until until [ "$yn" == "no" -o "$yn" == "NO" ] do read -p "Please input no/NO to stop this program:" yn done echo "OK! you input the correct answer"
for調試
#for function printAnimal() { for animal in $@ do echo "$animal" done } printAnimal cat dog elephant user=$(cut -d ':' -f1 /etc/passwd) for username in $user do echo "$username" done s=0 nu=12 for(( i=1; i<=$nu ; i=i+1)) do s=$(($s + $i)) done echo "The result of '1+2+3+...+12' is ==> $s"
script調試code
sh -x 20150810loop.shblog
能夠看到完整的執行過程,好比上文代碼中的最後一個循環ip