Kolam Ayer MakersLinux Foundations

[[ ]]

Use

[[ -e "$path" ]]

What It Does

[[ ]] is Bash’s conditional expression syntax. It tests strings, files, numbers, and patterns, then returns success or failure.

File Tests

[[ -e "$path" ]]
[[ -f "$path" ]]
[[ -d "$path" ]]
[[ -x "$path" ]]

String Tests

[[ -z "$name" ]]
[[ -n "$name" ]]
[[ "$name" == "Ada" ]]
[[ "$name" == A* ]]

Numeric Tests

[[ "$count" -gt 0 ]]
[[ "$count" -eq 10 ]]

Use -gt, -lt, -eq, -ne, -ge, and -le for integer comparisons.

Watch Out

Docs Pointers