與其他編程語言類似,Shell支持for循環。
for循環一般格式為:
當變量值在列表里,for循環即執行一次所有命令,使用變量名獲取列表中的當前取值。命令可為任何有效的shell命令和語句。in列表可以包含替換、字符串和文件名。
in列表是可選的,如果不用它,for循環使用命令行的位置參數。
例如,順序輸出當前列表中的數字:
輸出:
The value is: 1
The value is: 2
The value is: 3
The value is: 4
The value is: 5
順序輸出字符串中的字符:
輸出:
This is a string
新聞熱點
疑難解答