新聞中心
除了 while 循環(huán)和 until 循環(huán),Shell 腳本還提供了 for 循環(huán),它更加靈活易用,更加簡潔明了,下面為大家簡單介紹一下shell for循環(huán)的使用方法。

作為一家“創(chuàng)意+整合+營銷”的成都網(wǎng)站建設(shè)機構(gòu),我們在業(yè)內(nèi)良好的客戶口碑。創(chuàng)新互聯(lián)公司提供從前期的網(wǎng)站品牌分析策劃、網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、網(wǎng)站制作、創(chuàng)意表現(xiàn)、網(wǎng)頁制作、系統(tǒng)開發(fā)以及后續(xù)網(wǎng)站營銷運營等一系列服務(wù),幫助企業(yè)打造創(chuàng)新的互聯(lián)網(wǎng)品牌經(jīng)營模式與有效的網(wǎng)絡(luò)營銷方法,創(chuàng)造更大的價值。
for循環(huán)一般格式為:
for var in item1 item2 ... itemN
do
command1
command2
...
commandN
done
寫成一行:
for var in item1 item2 ... itemN; do command1; command2… done;
當變量值在列表里,for循環(huán)即執(zhí)行一次所有命令,使用變量名獲取列表中的當前取值。命令可為任何有效的shell命令和語句。in列表可以包含替換、字符串和文件名。
in列表是可選的,如果不用它,for循環(huán)使用命令行的位置參數(shù)。
例如,順序輸出當前列表中的數(shù)字:
for loop in 1 2 3 4 5
do
echo "The value is: $loop"
done
輸出結(jié)果:
The value is: 1
The value is: 2
The value is: 3
The value is: 4
The value is: 5
順序輸出字符串中的字符:
for str in 'This is a string'
do
echo $str
done
輸出結(jié)果:
This is a string
標題名稱:詳解shellfor循環(huán)
網(wǎng)頁路徑:http://m.fisionsoft.com.cn/article/copgoih.html


咨詢
建站咨詢
