Concept Flow - [[ ]] extended test
Start
Evaluate [[ expression
Is expression true?
No→Execute else or skip
Yes
Execute then block
End
The [[ ]] extended test evaluates a condition. If true, it runs the then block; if false, it runs else or skips.
if [[ -f /etc/passwd && -r /etc/passwd ]]; then echo "File exists and is readable" else echo "File missing or not readable" fi
| Step | Expression Evaluated | Result | Branch Taken | Output |
|---|---|---|---|---|
| 1 | -f /etc/passwd | true | Continue | |
| 2 | -r /etc/passwd | true | Continue | |
| 3 | -f /etc/passwd && -r /etc/passwd | true | Then block | File exists and is readable |
| 4 | End of if | N/A | Exit |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| -f /etc/passwd | N/A | true | true | true |
| -r /etc/passwd | N/A | N/A | true | true |
| Combined expression | N/A | N/A | N/A | true |
[[ ]] extended test syntax: if [[ condition ]]; then commands fi Supports complex tests with &&, ||, pattern matching. Returns true or false to control flow. Use for safer, more powerful condition checks.