码迷,mamicode.com
首页 > 系统相关 > 详细

shell for的用法

时间:2016-10-09 12:57:50      阅读:701      评论:0      收藏:0      [点我收藏+]

标签:

#!/bin/sh

for1(){

for i in 1 2 3 4 5 6
do
echo "$i"
done

}


for1
#!/bin/sh
for2(){
for i in {1..10}
do
echo "$i"

done


}

for2
#!/bin/sh

for3(){

sum=0
#int=1

for i in {1..100..2}
do
let "sum+=i"
done

echo "sum is $sum"
}

for3
#!/bin/sh

for4(){
sum=0

for i in $(seq 1 2 100)
do
let "sum+=i"
done

echo "sum is $sum"
}

for4
#!/bin/sh

for5(){

for file in $(ls)

do
echo "file: $file"
done
}

for44(){

for file1 in $( ls )

do
echo "file: $file1"
done


}


#for5
echo "*****************"
for44
#!/bin/sh

echo "the number of arguments is $#"

for i in "$*"
do
echo "$i"
done
#!/bin/sh
for8(){
sum=0
for ((int=1;int<200;int++))
do
let "sum+=int"

done

echo "the sum is $sum"

}


for8
#!/bin/sh

for9(){
sum=1


for (( i=9;i>0;i-- ))
do
echo "$i"
let "sum*=i"
done

echo "the sum is $sum"

}

for9

shell for的用法

标签:

原文地址:http://www.cnblogs.com/luo-mao/p/5941387.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!