"Simplest dead loop" "Turn" of shell script programming

Source: Internet
Author: User

Transferred from: http://blog.chinaunix.net/uid-23046336-id-3475462.html

Programs programmed under Linux apes know shell scripts, and even if you're not familiar with them, you should have heard them! What about the dead loop in the shell script?

For apes who are familiar with C, the simplest cycle of death should be written like this:

-------------------------------------------------------------------------

while (1)

{

Do something

}

------------------------------------------------------------------------

Or you can do it with a for statement and a do...while statement, not here!

But how do you write a dead loop in a shell script?

To the shell is not familiar with the ape man, believe that this problem must have baffled everyone, anyway this problem once baffled me ...

Google on the internet after a look at some information, I suddenly dawned! The original can be written like this:

------------------------------------------------------------------------

While ["1" = "1"]

Do

# do something

Done

------------------------------------------------------------------------

Or

------------------------------------------------------------------------

While test "1" = "1"

Do

# do something

Done

------------------------------------------------------------------------

Perhaps, you will think and C language a bit like, sure! But please note that this is a script!

See here you may know how to write a dead loop in the shell, but is this really the simplest cycle of death?

Not really! The simplest dead loop should be written like this, (note: I'm here to call it the simplest, and perhaps the simplest!) )

------------------------------------------------------------------------

While:

Do

# do something

Done

------------------------------------------------------------------------

See here, perhaps you will be very puzzled son, this is what thing, even suspicion I in "stride"-----"pull an egg", actually my step is small, absolutely can't pull the egg!

Yes, it is indeed a cycle of death, do not believe you can try! Note that "#" is the meaning of the comment line in the shell, except for this #!/bin/sh

There is ":" in the shell to represent an empty statement, is nothing to do! Equivalent to ";" In C!

All right, here we go!

Thanks for browsing!

"Simplest dead loop" "Turn" of shell script programming

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.