Shell script loop using for while explanation

Source: Internet
Author: User

Loops in any programming language are more than enough, and of course the shell script also has a looping statement, including a for statement, while statement. This article mainly uses the actual use case to illustrate what common use methods and techniques are used for the while.

one, for loop use

1. SEQ Command mode

 for  in $ (seq);  do    Echo " $i "  Done

2. C Language Grammar method

 for ((i=0; i<9; i++));  do    Echo " $i "  Done

3. Looping through a list of files

 for file  in $ (lsdoes    echo"$file" Done

4. Looping through array elements

 for inch  do    Echo " $i "  Done

5. Looping through the script parameter list

 for inch  do    Echo " $arg "  Done

6. Explicitly specifying a list

 for inch 1 2 3 ;  do    Echo $i  Done

7. List for loop

 for inch {1.. 5  do    Echo " $i "  Done

8. Step-Count jumping mode for loop

 for inch {1.. . 2};  do    Echo " $i "  Done

second, while loop use

1. Common while syntax

 while ((i<= ));  Do     ... ...  Done
 while " $num " 4  Do     ... ...  Done
 while " $num " 0  Do     ......  Done

Pending update ...

Shell script loop using for while explanation

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.