ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

Shell±à³Ìѧϰ֮ѭ»·
2014-11-24 12:46:58 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:1´Î
Tags£ºShell ±à³Ì ϰ֮ Ñ­»·

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


¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºShell¼à¿Ø´ÅÅ̲¢´òÓ¡³ö´ÅÅÌ ÏÂһƪ£ºShell±à³Ìѧϰ֮º¯Êý

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Linuxϵͳ¼ò½é (2025-12-25 21:55:25)
¡¤Linux°²×°MySQL¹ý³Ì (2025-12-25 21:55:22)
¡¤Linuxϵͳ°²×°½Ì³Ì£¨ (2025-12-25 21:55:20)
¡¤HTTP Åc HTTPS µÄ²î„ (2025-12-25 21:19:45)
¡¤ÍøÕ¾°²È«±ØÐ޿ΣºÍ¼ (2025-12-25 21:19:42)