#每日Linux小练习#08 Shell Script知识点总结(下)

 

今天对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

相关文章
相关标签/搜索