If condition test Type: File test, digital test, string test
If statement structure:
-
If ...; Then ...; Fi
-
If ...; Then ...; else ...; Fi
Conditional test expression:
- [Expression]
- [[Expression]]
- Test expression
Digital test: Note
- Only integer tests are possible
- if test 3-eq $V 2 equivalent to If [3-eq $V 2]
"3-eq $V 2" equals
"3-ne $V 2" range
"3-lt $V 2" is less than
-le less than or equal to-gt greater than-ge greater than or equal
String test:Note
- When you want to make a decimal comparison, you cannot use the method of the number test, use a string test
- String comparison in Shell is only =, no = =
- String testing is best done using "" to bring up strings
[[$V = $v]] Pattern match if the 4 starts with true
[[$V = "["]] character match if $v equals to True
[-Z "$V"]-Z means the string is empty
[-N "$V"]-n means the string is not empty
File test:
-e file Test files exist
-F file Test is a normal file
-D FILE Test Specifies whether the path is a directory
。。。
A good solution to writing a case:
- To determine the NFS version
For V in ...
Lockp=lockd
[$V = []] && LOCKP=NFSD
SSH $SERVER $lsLocks | grep $LOCKP
Done
1. Package the lock, then use SSH to execute command 2. Use simplified if judgment
If Judgment statement in Shell