linux教程for语句,Shell脚本for循环语句简明教程
生活随笔
收集整理的這篇文章主要介紹了
linux教程for语句,Shell脚本for循环语句简明教程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
與其他編程語言類似,shell支持for循環。
for循環一般格式為:
for 變量名 in 列表
do
command1
command2
...
commandn
done
當變量值在列表里,for循環即執行一次所有命令,使用變量名獲取列表中的當前取值。命令可為任何有效的shell命令和語句。in列表可以包含替換、字符串和文件名。
in列表是可選的,如果不用它,for循環使用命令行的位置參數。
例如,順序輸出當前列表中的數字:
for loop in 1 2 3 4 5
do
echo "the value is: $loop"
done
輸出:
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
輸出:
this is a string
總結
以上是生活随笔為你收集整理的linux教程for语句,Shell脚本for循环语句简明教程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux工科软件,linux基础网络工
- 下一篇: mac on linux,Mac- on