shell的for循环

一 语法
for 变量 in 值1 值2 值3
do
程序
done
 
二 实战
#!/bin/bash
for i in 1 2 3 4 5
do
echo $i
done
 
三 测试
[root@localhost shell]# ./shell9.sh
1
2
3
4
5
 
四 for循环实现解压缩
#!/bin/bash
 
cd /root/test/
ls *.tar.gz > ls.log
ls *.tgz >> ls.log
 
for i in $(cat ls.log)
do
tar -zxf $i &>/dev/null
done
rm -rf ls.log

猜你喜欢

转载自cakin24.iteye.com/blog/2393313