if [ 條件判斷式 ];then
程序
fi
或者
if [ 條件判斷式 ]
then
程序
fi
----------------------------
#!/bin/bash
if [ $1 -eq "1" ]
then
echo "11111111111111"
elif [ $1 -eq "2" ]
then
echo "222222222222222"
fi
case語句
----------------------------
#!/bin/bash
case $變量名 in
"值1")
如果變量的值等於值1,則執行程序1
;;
"值2")
如果變量的值等於值2,則執行程序2
;;
…省略其他分支…
*)
如果變量的值都不是以上的值,則執行此程序
;;
esac
----------------------------
case $1 in
"1")
echo "11111111111111"
;;
"2")
echo "cls"
;;
*)
echo "222222222222"
;;
esac
for 循環
for (( 初始值;循環控制條件;變量變化 ))
do
程序
done
----------------------------
#!/bin/bash
s=0
for((i=0;i<=100;i++))
do
s=$[$s+$i]
done
echo $s
----------------------------
for 變量 in 值1 值2 值3…
do
程序
done
----------------------------
#!/bin/bash
A=0
for i in $1 $2 $3
do
A=$[$1+$2+$3]
done
echo $A
while
while [ 條件判斷式 ]
do
程序
done
----------------------------
#!/bin/bash
s=0
i=1
while [ $i -le 100 ]
do
s=$[$s+$i]
i=$[$i+1]
done
echo $s