shell±à³Ìѧϰ֮ѻ·
1¡¢for----do.......doneµÚÒ»ÖÖÑ»·
-bash-3.2# cat test.sh
#!/bin/bash
for var in 1 2 3 4 5
do
echo $var
done
-bash-3.2# sh test.sh
1
2
3
4
5
2¡¢for----do.......doneµÚ¶þÖÖÑ»·
-bash-3.2# cat test.sh
#!/bin/bash
for var in `seq 5`
do
echo $var
done
-bash-3.2# sh test.sh
1
2
3
4
5
3¡¢for----do.......doneµÚÈýÖÖÑ»·
-bash-3.2# cat test.sh
#!/bin/bash
for ((i=1;i<=5;i++))
do
echo $i
done
-bash-3.2# sh test.sh
1
2
3
4
5
4¡¢for----do.......doneµÚËÄÖÖÑ»·
-bash-3.2# cat test.sh
#!/bin/bash
a='frefef'
len=`echo ${#a}`
for ((i=1;i<=$len;i++))
do
echo $i
done
-bash-3.2# sh test.sh
1
2
3
4
5
6
5¡¢for----do.......doneµÚÎåÖÖǶÈëÑ»·
-bash-3.2# cat test.sh
#!/bin/bash
a='fre'
len=`echo ${#a}`
for ((i=1;i<=$len;i++))
do
for j in 1 2 3
do
echo "$iºÍ$j±È½Ï´óС²âÊÔ"
done
done
-bash-3.2# sh test.sh
1ºÍ1±È½Ï´óС²âÊÔ
1ºÍ2±È½Ï´óС²âÊÔ
1ºÍ3±È½Ï´óС²âÊÔ
2ºÍ1±È½Ï´óС²âÊÔ
2ºÍ2±È½Ï´óС²âÊÔ
2ºÍ3±È½Ï´óС²âÊÔ
3ºÍ1±È½Ï´óС²âÊÔ
3ºÍ2±È½Ï´óС²âÊÔ
3ºÍ3±È½Ï´óС²âÊÔ
6¡¢ while.....do.......done
-bash-3.2# cat test.sh
#!/bin/bash
i=1
while [ $i -le 5 ]
do
echo $i
i=$((i+1)) ##ʵÏÖi++£¬Ò²¿ÉÒÔlet
done
-bash-3.2# sh test.sh
1
2
3
4
5
7¡¢untilÑ»·
#!/bin/bash
i=1
until [ $i -gt 5 ]
do
echo $i
let i++
done