Bash无限循环Shell Linux

How can write infinite shell that will run forever? May be I need a 5 second sleep between steps. Recently I have a issue with my routing table and I need to remove some route automatically every 5 minutes. I came up with a solution that runs every 4 minutes and clears unwanted routes.

如何编写将永远运行的无限shell? 在步骤之间可能需要5秒钟的睡眠时间。 最近,我的路由表出现问题,我需要每5分钟自动删除一些路由。 我想出了一种解决方案,该解决方案每4分钟运行一次,清除不需要的路由。

而无限循环 (While Infinite Loop)

There are a lot of different ways do express our solution one of them is when loop of bash. We will provide true to the while.

有很多不同的方式向你表达我们对他们的解决方案之一是庆典的时候循环。 我们将提供truewhile

$ while true; do echo "test"; sleep 5; done
While Infinite Loop
While Infinite Loop
而无限循环

Here while true runs loop forever between do and done is run regularly but sleep 5 makes the script or each step to wait 5 seconds. We can cancel script with CTRL+C.

在这里,虽然true运行永远在dodone之间循环,但定期运行,但是sleep 5使脚本或每个步骤等待5秒。 我们可以使用CTRL + C取消脚本。

对于无限循环 (For Infinite Loop)

We can also implement infinite loops with the for . We will provide ( ; ; ) to the for loop which means infinite loop. We will print test to the console forever with 5 seconds intervals.

我们还可以使用for实现无限循环。 我们将为for循环提供( ; ; ) ,这意味着无限循环。 我们将每隔5秒将test永久打印到控制台上。

$ for (( ; ; )) do echo "test"; sleep 5; done
For Infinite Loop
For Infinite Loop
对于无限循环

Bash无限循环Shell Linux Infografic(Bash Infinite Loop Shell Linux Infografic)

LEARN MORE  How To Download and Install Linux Bash Shell On Windows 10?
了解更多如何在Windows 10上下载并安装Linux Bash Shell?

翻译自: https://www.poftut.com/bash-infinite-shell-linux/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值