Linux中的for循环

来源:互联网 发布:机械建模软件 编辑:程序博客网 时间:2024/04/30 15:03
1 方法1

1.1 简单打印元素

#!/bin/bash
for i in a b c d e f
        do
                echo "the elment is $i"
        done

1.2 批量解压文件
#!/bin/bash
dir=/home/shell_study3
tmpdir="$dir/tmp/"
cd $dir

ls *.log.tar.gz > ls.log
for i in $(cat ls.log)
do
tar -zxvf $i -C $tmpdir &>/dev/null
done
rm -rf ls.log
echo 'ok'


2 方法2

#!/bin/bash
sum=0
for ((i=1;i<=100;i++))
do
sum=$(($sum+$i))
done
echo "the sum is $sum"

1 0