Tsallaka zuwa abun ciki
Justice Tech School

Test Operators

Inside [[ ]] use -eq -ne -gt -lt for numbers, == != for strings, -z for empty and -n for non empty, and -e -f -d -r -w -x for files. ! negates and && || combine.

Example
a=5; s=""
[[ $a -gt 3 ]] && echo "gt"
[[ -z $s ]] && echo "empty"
[[ -n "abc" ]] && echo "non empty"
[[ -d /tmp && -w /tmp ]] && echo "tmp writable"
[[ $a -eq 5 || $a -eq 6 ]] && echo "5 or 6"

Result

gt
empty
non empty
tmp writable
5 or 6

Exercise

Test for an empty string.

[[  $s ]]

Quiz Test

Which tests that a file exists?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.