ENV:
[root@Fedora31 ~]# uname -r
5.5.15-200.fc31.x86_64
[root@Fedora31 ~]# 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