Shell腳本之流程控制語句
1、 if語句
(1)if 條件;then
action1
else
action2
fi
注意:shell里沒有縮進要求。
(2)if 條件1;then
action1
elif 條件2;then
action2
elif 條件3;then
action3
else
action4
fi
示例:
#!/bin/bash
declare -i n1=10
declare -i n2=10
if [[ $n1 -gt $n2 ]];then
echo
“$n1 > $n2”
elif [[ $n1 -lt $n2 ]];then
echo
“$n1 < $n2”
else
echo “$n1 = $n2”
fi
2、for循環
for 變量名 in 列表
do
命令1
命令2
done
示例:
for I in {1..10};do
echo “$I”
done
3、 while循環
while 條件或者true或((1))
do
action
done
示例:
#!/bin/bash
a=10
while true ; do
echo $a
done
原創文章,作者:張 潔,如若轉載,請注明出處:http://www.www58058.com/73452