|
The Basic if statement syntax: |
|
|
Output:
This always runs |
|
|
The |
|
|
Output:
/tmp exists and is readable |
|
|
Use the Numeric comparisons:
|
|
|
Output:
Value is 10 Count is greater than 3 |
|
|
String comparisons use |
|
|
Output:
Hello, Alice! Hello, not Bob! |
|
|
All |
|
|
Output:
Variable is empty Variable is not empty |
|
|
File |
|
|
Output:
/etc/passwd exists and is a file /tmp exists and is a directory |
|
|
Always quote variables in tests to handle empty values and spaces correctly. |
|
|
Output:
sh: some_value: unknown operand |
|
|
Bash
Bash provides extended test syntax With |
|
|
Output:
Hello, Alice! |
|
|
Bash
Bash supports pattern matching with |
|
|
Output:
It's a text file |
|
|
Bash
Regex matching with |
|
|
Output:
Valid email format |
|
|
Bash
Bash also provides |
|
|
Output:
Count is greater than 3 x is between 0 and 100 |
|