Monday, 2 Mar 2026
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  UK Power Networks becomes first DNO to partner with DCA

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

Swivel Raises $5.8M in Series A Funding

Swivel (fka PilotDesk), a NYC-based supplier of a no-code AI workflow automation platform for promoting…

April 30, 2025

Confident Security Raises $4.2M in Funding

Confident Security, a San Francisco, CA-based know-how enabling provably non-public AI interactions, raised $4.2M in…

July 18, 2025

Digital Realty appoints Paula Cogan as Managing Director, Head of EMEA Region

Cogan brings over 20 years of European telecommunications and infrastructure expertise to Digital Realty. Most…

February 27, 2025

Camber, a San Francisco, CA-based provider of a cloud-based computing platform, raised $4M in Seed funding.

Camber, a San Francisco, CA-based supplier of a cloud-based computing platform, raised $4M in Seed…

March 23, 2025

Nvidia’s Next-Generation AI Chip Rollout Slowed by Engineering Snags

(Bloomberg) -- Nvidia Company hit engineering snags within the growth of two new superior chips,…

August 6, 2024

You Might Also Like

shutterstock 440449237 gush of water from a fountain
Global Market

Raising the temp on liquid cooling

By saad
Close-up cropped view portrait of his he nice attractive skilled professional smart focused guy monitoring client
Global Market

New Relic connects observability platform to business outcomes

By saad
Data center / enterprise networking
Global Market

HPE’s latest Juniper routers target large‑scale AI fabrics

By saad
Panoramic high speed technology in big city concept, light abstract background.
Global Market

Netskope targets AI-driven network bottlenecks with AI Fast Path

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.