Shell:while语句、for语句、if语句
for:
#打印123
for i in {1,2,3}; do
echo -n $i
done
#打印abcd
for i in {a..d}; do
echo -n $i
done
#可以用这种循环方式
for ((i=0; i<10; i++)){
echo $i
}
while:
i=5
while [ $i -gt 3 ]; do
echo $i
let i--
done
until:
i=5
until [ $i -eq 7 ]
do
echo $i; let i++
done
if:
if [ 3 -lt 2 ]; then
echo "3<2"
elif [ 3 -gt 2 ]; then
echo "3>2"
else
echo "3==2"
fi
#组合多个条件:
if [[ "a" == "a" ]] && [ 3 -eq 2 ]; then echo "T"; else echo "F"; fi
#使用test测试条件:
if test 3 -eq 3; then echo "T"; fi