判断:
if command1
then
command
command
....
else
command
command
...
fi
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
case 命令:
case value in
pat1) command
command
....
command;;
pat2) command
...
command;;
...
esac
举例:
case $1 in
0) echo zero;;
1) echo one;;
2) echo two;;
.
.
.
esac
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
for循环
for var in word1 word2....wordn
do
command
command
.....
done
举例:
如果想用run程序执行一组文件,文件名列表存放在filelist文件中。
files=$(cat filelist)
do
run $file
done
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
while 循环
while command1
do
command
command
...
done
举例:
循环读出一个文件,并加入行号。
lineno=1
cat $* | while read line
do
echo "$lineno: $line"
lineno=$(($lineno + 1))
done
阅读(283) | 评论(0) | 转发(0) |