shell—if case while for

if

if [ 1 -gt 2 ]
then
        echo '1 > 2'
else
        echo '1 <= 2'
fi

 

 

if [ 1 -gt 2 ]
then
        echo '1 > 2'
elif [ 1 = 2 ]
then
        echo '1 = 2'
else
        echo '1 < 2'
fi

 

case

case $1 in
y)
        echo 'yes'
        ;;
Y)
        echo 'yes'
        ;;
n)
        echo 'no'
        ;;
N)
        echo 'no'
        ;;
esac

 

 

for

for name in zhangsan lisi wangwu
do
        echo $name
done

 

 

while

i=0
while [ $i -lt 10 ]
do
        echo $i
        i=`expr $i + 1`
done

posted @ 2013-11-06 08:52  helloweworld  阅读(188)  评论(0编辑  收藏  举报