Shell script programming: "The simplest endless loop"

Source: Internet
Author: User

The "simplest endless loop" of shell script programming programmers in linux all know shell scripts. Even if you are not familiar with them, you should have heard of them!
So how to write an endless loop in a shell script? Www.2cto.com for those familiar with C language, the simplest endless loop should be written like this: ------------------------------------------------------------ while (1) {// do something} --------------------------------------------------------------- or you can use the for statement and do... the while statement! But how do I write an endless loop in a shell script? Www.2cto.com is a shell-unfamiliar ape. I believe this problem will be difficult for everyone. It has been a problem for me ...... I suddenly realized that I had accessed some information on the Internet and google! It can be written like this: When while ["1" = "1"] do # do somethingdone then or when while test "1" = "1" do # do somethingdone then maybe, you may think it's a little different from the C language! But please note that this is a script! You may know how to write an endless loop in shell, but is this really the simplest endless loop? Actually not! The simplest endless loop should be written in this way. (Note: I call it the simplest here, and it may be simple !) Www.2cto.com when: do # do somethingdone when you see this, maybe you will be bored, what is this thing, and even suspect that I am in the "big step" ----- "nonsense", in fact, my step is very small, and I can't find it! Yes, this is indeed an endless loop. If you don't believe it, you can try it! Note "#" the meaning of this line is commented in shell, #! /Bin/sh and ":" empty statement in shell, that is, nothing is done! It is equivalent to ";"! Well, I will write it here! Thank you!

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.