Saturday, 11 Apr 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  Bash command cheat sheet | Network World

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

Dallas’ DataBank to build $256 million project in Red Oak

Information middle firm DataBank Inc. has plans to construct a greater than 425,000-square-foot facility within…

June 14, 2024

Share Your Expertise with the Data Center Community

For over 15 years, Trade Views has been a trusted platform for thought management in…

November 19, 2025

Global Edge Data Center Industry Research 2023-2033

Dublin, April 01, 2024 (GLOBE NEWSWIRE) -- The "Edge Data Center Market - A Global…

April 1, 2024

Splash Raises $4.5M in Pre-Seed Funding

Splash, a San Diego, CA-based startup aiming to remodel the pool service business, closed a $4.5m…

April 6, 2024

Equinix Plans USD 94 Million Investment in Third Rio de Janeiro Data Center, Brazil

Equinix has introduced a USD 94 million funding in its third knowledge centre (RJ3) in…

May 26, 2024

You Might Also Like

Large AWS sign. Amazon Web Services (AWS) is a subsidiary of Amazon that provides on-demand cloud computing platforms - Las Vegas, Nevada, USA - December 3, 2019
Global Market

AI demand is so high, AWS customers are trying to buy out its entire capacity

By saad
Why sovereignty now shapes data centre planning in Europe
Global Market

Why sovereignty now shapes data centre planning in Europe

By saad
Heat emission from the chimneys of a large data and server complex.
Global Market

OpenAI puts part of Stargate project on hold over runaway power costs

By saad
EMEA data centre vacancy hits record low as AI demand outpaces supply
Global Market

EMEA data centre vacancy hits record low as AI demand outpaces supply

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.