Shell script-Conditional statement, loop statement

Source: Internet
Author: User
Tags case statement

Conditional statements

1#!/bin/Bash2 3Read-p"input your name:"name4 #第一种判断5 if["$name"=="Mike" ];then #注意这里用 [...] When comparing two strings, the variable $name  quoted, and there are spaces on both sides of "= ="; "[" followed by a space; "]" preceded by a space 6     Echo "eq"7 Else8     Echo "Not eq"9 fiTen  A#The second kind of judgment - ifTest$name="Mike";Then #注意这里用 Test compares two strings, the variable $name is not quoted , and "=" has spaces on both sides -     Echo "eq" the Else  -     Echo "Not eq" - fi

The first judgment and the second is equivalent.

Case statement

1#!/bin/Bash2 3Read-p"input your name:"name4 5  Case$nameinch 6     "Mike" )7         Echo "You are Mike"8      ;;9     "Tom" )Ten         Echo "You are Tom" One     ;; A*) #相当于通配符, 0~ Infinite number of arbitrary characters -         Echo "anything" -     ;; the Esac

Cycle

1  while[Condition] #表示condition成立时, execute2  Do3 #程序段落4  Done5 6 7 until[condition] #表示condition不成立时, execution, or, if established, exit the loop8  Do9 #程序段落Ten  Done One  A  -  forVarinchcon1 con2 con3 ... # first cycle, $var content is con1; second time is con2 .... -  Do the #程序段落 -  Done -  -  +  for((i=1; i< -; i=i+1)) -  Do +s=$ (($s +Si)) A  Done

Shell script-Conditional statement, loop statement

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.