Linux中的for循环

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

                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"

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/hdsghtj/article/details/84099499