标签:for
shell脚本中的循环
for循环 语法结构: for 变量名 in 条件; do … done
例:
#!/bin/bash
sum=0
for i in `seq 1 100`
do
sum=$[$sum+$i]
echo $i
done
echo $sum
例:
#!/bin/bash
cd /etc/
for a in `ls /etc/`
do
if [ -d $a ]
then
ls -d $a
fi
done
例:
#!/bin/bash
n=`wc -l 1.txt |awk ‘{print $1}‘`
for i in `seq 1 $n`
do
sed -n "$i"p 1.txt
done
标签:for
原文地址:http://xiongrunchu.blog.51cto.com/11696174/1787510