shell语句总结:
1.开头必须的
#!/bin/sh
2.echo 输出结果
3.if语句
if[ -d $1] then echo "this is a directoty!"elif [ -f $1 ] then echo "is a file!"else echo "this a ..."fi
4.for 语句
for var in 1 2 3 4 5 6 7 8 9 10do echo "number is $var"done
5.select语句
select var in "java" "c++" "php" "linux" "python" "ruby" "c#" do breakdoneecho "you selected $var"
6.case语句
#!/bin/shread opcase $op in a) echo "you selected a";; b) echo "you selected b";; c) echo "you selected c";; *) echo "error"esac7.while语句
#!/bin/shnum=1sum=0while [ $num -le 100 ]do sum=`expr $sum + $num` num=`expr $num + 1`doneecho $sum
8.while语句与if语句相结合
#!/bin/shi=0while [ $i -le 100 ]do i=`expr $i + 1` if [ $i -eq 5 -o $i -eq 10 ] then continue; else echo "this number is $i" fi if [ $i -eq 15 ] then break; fi done