条件与循环控制:
在shell中0是表示true,1是表示false,同时也可以用冒号“:”表示true
也可以直接if 1/0 或者if true 或者 if :;then
statement
fi
或者while 1
#!/bin/sh
if [ condition ]
then
statements
else
statements
fi
exit 0
或者if [ condition ];then
elif语句
if [ condition ]
then
statements
elif [ condition];then
statements
else
statements
fi
exit 0
2.for 循环
for variable in values
do
statements
done
可以用通配符来扩展for循环,如
for file in $(ls f*.sh);do
lpr $file
done
exit0
3.while循环
while condition; do
statements
done
4.until condition;do
statemments
done
知道condition条件为真才结束循环,至少执行一次
5.case语句
case variable in
pattern [ | pattern]) statements
statements2
statements3 #可以执行多条语句
;;
pattern [ | pattern]) statements;;
esac
6.and 与 or
statements && statements #如果前面语句为错,后面语句不执行
statements || statements #如果前面语句为true,后面语句不执行