Basic syntax structure summary of Shell programming basics

Source: Internet
Author: User

First, conditional statements
  • Simple conditions
    if  Then     # When the condition is established, the content is executed;fi  If the reverse is written, the meaning offiif
  • Complex conditions

    if  Then     # When condition is established, execute content;else    # When condition is established, the content is executed;fi
    if  Then     # When Condition1 is established, the content is executed;elifthen    # When the Condition2 is established, the content is executed; Else     # When Condition1 and Condition2 are not established, the content is executed;fi
Second, the circular statement
  • for
     for  var in   Con1 con2 Con3 ...  do   # Execute content  done  

    note : Con1,con2,con3 is a list of strings, separated by spaces

     for  var in   {min... Max}  do   # Execute content  done  

    note : Min is called decimal, Max is a larger number, step is 1.

     for   (initial value; limit value; step)  do   done  
  • While
     while [Condition]  # when the condition condition is established, loop until the condition is not set to stop do     # execution content
    Done
  • UNTIL

    until [Condition]  # And while in contrast, when the condition condition is true, the loop is terminated, or the program segment of the loop continues to do the content     
     Done
III. SELECT statements
  • case
     case  $ variable in   "  first variable content  "     second variable contents   ) # execute content;;  *) # The last variable content will be used * to represent all other values, but not the contents of the first variable with the contents of the second variable run segment # execution content;;  esac  # The end of the case ending in an anti-write   
  • SELECT
    Select inch con1 con2 con3    # automatically lists Con1,con2,con3 's selection menu do     #执行内容break    # Select itself is a loop, Break is when you choose to jump out of the loop done 

    Note: Select is an extension of bash, automatic read input selection sequence, and pass selection to variable

Basic syntax structure summary of Shell programming basics

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.