Shell programming Conditional judgment----use case ... ESAC judgment

Source: Internet
Author: User

Conditional judgment----Use case ... ESAC judgment

Case $ variable name in <== keyword for case, there are variables before rich font size

"First variable content") <== the contents of each variable are suggested to be enclosed in double quotation marks, and the key words are parentheses.

Program Segment

;; <== use two consecutive semicolons to handle each category end!

"Second variable content")

Program Segment

;;

*) <== The last variable content will use * to represent all other values

Other program execution segments that do not contain the contents of the first variable and the contents of the second variable

Exit 1

;;

Esac <== The final case ending! "Turn to write" Think about it!

It is important to note that this syntax begins with the case (the meaning of the actual cases), and the end is naturally written in the English language in turn! Just be ESAC! It won't be hard to recite!

In addition, each variable content of the program section will need two semicolon (;;) to represent the end of the program paragraph, which is very important!

As to why it is necessary to have * this variable content at the end? This is because if the user is not the input variable content one or two o'clock, we can inform the user of the relevant information Ah! Say less nonsense, case description

The source program is as follows:

1  Case$1 inch2 "Hello")3Echo"hello,how is you?"4         ;;5 "")6Echo"You must input parameters,ex>{$0 Someword}"7         ;;8*) #其实就相当于通配符,0~Infinite number of arbitrary characters meaning! 9Echo"Usage $ {Hello}"Ten         ;; OneEsac

To create a shell script with the VI editor:

To write a shell script with the VI editor:

The results of the implementation are as follows:

In the above sh09-2.sh case, if you enter "sh test02.sh test" to execute, then "usage test02.sh {Hello}" will appear on the screen, telling the performer to use only Hello Oh ~ such a way for some Fixed string to execute the variable content is more convenient! You really have to be familiar with this way! This is because many of the system's services start scripts using this notation.

Shell programming Conditional judgment----use case ... ESAC judgment

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.