shell programming - conditional statements

shell programming of conditional statements

According to predefined variables ($?) To determine whether they were successful, when returns 0 for success, when returns 1 indicates failure or abnormal.

 

test command to use:

test conditional expressions

[Conditional expression] used this way, note: before and after the conditional expression must be spaces

 

1, the test conditions

Determine whether the directories, files, if there is, authority

 

 

 

 

 

 Example:

 

 

 

 

 Determine whether the folder is returned yes, instead of no return

 

 

 

 

(2) comparing the value

Integer comparison:

 

 

 

Small numerical comparison:

Can not directly compare decimals

Comparison ideas: the use awk -F taken out and then compares the fractional part.

 

 

(3) string comparison

Is equal to

If not equal

Is empty

 

 

 

(4) determination logic

&& and test commands can be changed to -a

|| or test commands can be changed to -o

! Non -

[Conditional expression] wording

 

 

test conditional expressions wording

 

 

2, if sentence structure

(1) a single limb

 

 

(2) bis branch

 

 

(3) multi-branch

 

 

Guess you like

Origin www.cnblogs.com/zhuyunlong/p/11923353.html