Friday, 5 Dec 2025
Subscribe
logo
  • Global
  • AI
  • Cloud Computing
  • Edge Computing
  • Security
  • Investment
  • Sustainability
  • More
    • Colocation
    • Quantum Computing
    • Regulation & Policy
    • Infrastructure
    • Power & Cooling
    • Design
    • Innovations
    • Blog
Font ResizerAa
Data Center NewsData Center News
Search
  • Global
  • AI
  • Cloud Computing
  • Edge Computing
  • Security
  • Investment
  • Sustainability
  • More
    • Colocation
    • Quantum Computing
    • Regulation & Policy
    • Infrastructure
    • Power & Cooling
    • Design
    • Innovations
    • Blog
Have an existing account? Sign In
Follow US
© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
Data Center News > Blog > Global Market > How to loop forever in bash
Global Market

How to loop forever in bash

Last updated: November 11, 2024 9:58 am
Published November 11, 2024
Share
upside down roller coaster in a loop against a cloud and blue sky amusement park
SHARE

Contents
Utilizing forWhy loop without end?
whereas :
do
echo Maintain working
echo "Press CTRL+C to exit"
sleep 3
finished

You are able to do the identical factor in a single line by separating the strains proven above with semicolons as proven within the instance under.

whereas true; do echo Maintain working; echo 'Press CTRL+C'; sleep 3; finished

The command under would work the identical. I want whereas true as a result of it appears apparent, however any of the examples proven will work as does this one:

whereas [ 1 ]
do
echo Maintain working
echo "Press CTRL+C to exit"
sleep 3
finished

Utilizing for

The for command additionally gives a simple method to loop without end. Whereas not fairly as apparent as the whereas true choice, the syntax within reason simple. You possibly can simply substitute the parameters in a traditional for loop (the beginning, situation and increment values) that will usually look one thing like this:

$ for (int i = 0; i < 5; i++)

As a substitute, use the for command with no such values as within the instance under.

$ for (( ; ; ))
> do
> echo Maintain your spirits up
> echo “Press CTRL+C to exit”
> sleep 3
> finished
Maintain your spirits up
“Press CTRL+C to exit“
Maintain your spirits up
“Press CTRL+C to exit“
Maintain your spirits up
“Press CTRL+C to exit“

And, clearly, press CTRL-C if you need to exit the loop.

Why loop without end?

In fact, you’re not ever going to need to loop without end, however having loops run till you cease them can usually be very helpful. The script under runs till 5:00 p.m. It makes use of the date command with the +%H choice to verify the time, then reminds you that it’s time to go residence and exits. The sleep 60 command was included to restrict the time checking to as soon as a minute. In any other case, this script may gobble up lots of CPU time.

See also  Fortinet expands security lineup with sovereign SASE

Source link

TAGGED: bash, loop
Share This Article
Twitter Email Copy Link Print
Previous Article Cogna Raises $15M in Series A Funding Cogna Raises $15M in Series A Funding
Next Article New Planning Guidelines Set to Drive Growth New Planning Guidelines Set to Drive Growth
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Your Trusted Source for Accurate and Timely Updates!

Our commitment to accuracy, impartiality, and delivering breaking news as it happens has earned us the trust of a vast audience. Stay ahead with real-time updates on the latest events, trends.
FacebookLike
TwitterFollow
InstagramFollow
YoutubeSubscribe
LinkedInFollow
MediumFollow
- Advertisement -
Ad image

Popular Posts

Data Centers Face Critical Balancing Act As Grid Ages

What occurs when the digital spine of the UK, our knowledge facilities, meets the bodily…

September 26, 2025

D2X Raises $10M Series A Funding

D2X, an Amsterdam, The Netherlands-based crypto derivatives change firm for establishments, raised $10M in Collection…

March 19, 2024

The Advanced Nuclear Industry Would Like to Power Your Data Center

America’s know-how firms want energy, and many it.Synthetic intelligence mixed with still-growing web and smartphone…

March 23, 2024

RoboForce Raises $10M in Early Stage Funding

RoboForce, a Milpitas, CA-based “Robo-Labor” supplier, raised $10M in early stage funding. Backers included Nobel…

January 7, 2025

AWS Migration Competency Status Attained by Cloudelligent

Cloudelligent, a number one Managed Cloud Companies supplier, introduced as we speak that it has…

October 6, 2024

You Might Also Like

Council backs AI data centre plan despite BP’s hydrogen bid
Global Market

BP pulls out of Teesside hydrogen plant

By saad
Entry-level jobs AI
Global Market

CompTIA training targets workplace AI use

By saad
AVK and Rolls-Royce agree multi-year capacity deal
Global Market

AVK and Rolls-Royce agree multi-year capacity deal

By saad
fibre cables
Global Market

What is co-packaged optics? A solution for surging capacity in AI data center networks

By saad
Data Center News
Facebook Twitter Youtube Instagram Linkedin

About US

Data Center News: Stay informed on the pulse of data centers. Latest updates, tech trends, and industry insights—all in one place. Elevate your data infrastructure knowledge.

Top Categories
  • Global Market
  • Infrastructure
  • Innovations
  • Investments
Usefull Links
  • Home
  • Contact
  • Privacy Policy
  • Terms & Conditions

© 2024 – datacenternews.tech – All rights reserved

Welcome Back!

Sign in to your account

Lost your password?
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.
You can revoke your consent any time using the Revoke consent button.