|
|
|
The |
|
|
Basic if statement syntax: |
|
|
The |
|
|
Use the |
|
|
String comparisons use |
|
|
Check if a string is empty or non-empty. |
|
|
Numeric comparisons: -eq (equal), -ne (not equal) -lt (less than), -le (less or equal) -gt (greater than), -ge (greater or equal) |
|
|
File tests check file properties. |
|
|
Always quote variables in tests to handle empty values and spaces correctly. |
|
|
Bash
Bash provides extended test syntax [[ ]] which is safer and more powerful than single brackets. |
|
|
With [[ ]], quoting is often optional: |
|
|
Pattern matching with [[ ]]: |
|
|
Regex matching with =~: |
|
|
Bash also provides (( )) for arithmetic evaluation, which is cleaner for numeric comparisons: |
|