case...esac结构用来等量替换if... elif ... elif .. fi的结构。
examples:
-
#!/bin/bash
-
- arg="-f"
-
case $arg in
-
-f)
-
echo f...
-
;; #A must here
-
-d|--directory) #allow '|' for multiple matching
-
echo d...
-
;;
-
*) #'*' means default, recommended
-
echo w..$arg
-
;;
- esac
--------------------------------------------------------------------------
for语句
for 接受一个列表(若缺省,则列表为参数列表"$@"),并用迭代变量逐个遍历,执行循环体语句
-
for i in *; do file $i; done #单行形式
-
#或 # '*' 等价于 ls
-
for i in *
-
do
-
file $i
-
#code of works#
- done
- #also
- for i in `seq -w 0 100` #等宽输出
- do
- printf "%s\t" $i
- done
--------------------------------------------------------------------------
while-until 语句