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

你可能感兴趣的:(shell)