Linux Shell Learning Three

Source: Internet
Author: User

Shell for Loop

The syntax for the Shell for loop is as follows

 for inch List  Do     command1    command2    ... CommandN Done

Example:

 for inch {1..  - }  do      echo  $i   Done  

Class C language is also possible

 for ((i=1; i<=; i + +))    do      Echo $i    Done  
Shell while loop
 while Command  Do If True done     

Example:

counter=0while5  ]do    COUNTER='expr $ Counter+1'    echo  $COUNTER Done

Description: Returns True if counter is less than 5. Counter starting from 0, each time the loop is processed, counter plus 1, until count is 5 terminates.

Shell until loop
until Command  Do Until true done     

Example:

#!/bin/basha=0until [! $a-lt]do   echo $a   a= ' expr $a + 1 ' done

Note: When the "A is not less than 10" condition is false, the loop executes the command in the circulating body, that is, when a is greater than or equal to 10 o'clock, it will jump out of the loop body.

This script will output 0-9 numbers.

 

Linux Shell Learning Three

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.