Loops循环在shell中的使用

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

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值