Loops循环在shell中的使用
程序员文章站
2022-07-12 21:09:15
...
ENV:
[[email protected] ~]# uname -r
5.5.15-200.fc31.x86_64
[[email protected] ~]# cat /etc/redhat-release
Fedora release 31 (Thirty One)
循环的使用非常多,也是很有用的,不管是在编程中,还是在shell中,循环语句的使用可以节省大量的时间和空间。
循环的使用和C语言中的语法相差不大(基本可以说是一样)
这里不做实例操作,只是做为重要内容进行记录
For loop:
for var in list;
do
command; #use $var
done
list can be a string, or a sequence
#the variable i will hold a character in the range a to z:
for i in {a..z}; do actions; done;
the for loop can also take the format of the for loop in C.
for((i=o;i<10;i++))
{
commands;#use $i
}
While loop:
while condition
do
commands;
done
当condition为true时执行
Until loop:
x=0;
until [ $x -eq 9 ]; # [ $x -eq 9 ] is the condition
do let x++; echo $x;
done
推荐阅读
-
在Django中同时使用多个配置文件的方法
-
html5在android中的使用问题及技巧解读
-
C#中循环语句:while、for、foreach的使用
-
Python中for循环和while循环的基本使用方法
-
Python中在for循环中嵌套使用if和else语句的技巧
-
在C#中 webbrowser的使用心得
-
在PYQT5中QscrollArea(滚动条)的使用方法
-
关于C# 5.0 CallerMemberName CallerFilePath CallerLineNumber 在.NET4中的使用介绍方法
-
HTML5中微数据概述及在搜索引擎中的使用举例
-
HighCharts图表控件在ASP.NET WebForm中的使用总结(全)