shell编程-for
#!/bin/bash#shell中*替换
tot=0
for name in *
do
echo "file: $name"
tot=`expr $tot + 1`
done
echo "$tot files process working directroy in total"
#在for循环中省去in列表选项是,它将接收命令行参数作为参数
#等价于for num in $*
for para in $*
do
echo "param: $para"
done
#循环使用字符串
for str in "hello world" "nihao"
do
echo "string: $str"
done
#跟上面不同
out="first second third"
for str in $out
do
echo "string: $str"
done
#遍历命令得到的结果
for str in `ls -l | tail -n 2`
do
echo $str
done
#将当前目录下sh开头的文件,都以大写形式输出文件名
for file in `ls sh*`
do
echo $file | tr
done
页:
[1]