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