back toc next

Tests

test

test expression
or
[ expression ]
Test returns 0 (zero!) if expression is true and >0 if it is false.

Examples

Testing for empty string:
test -z "$variable"
[ -z "$variable" ]
[ x$variable != x ]
test if two strings are equal
test "$variable" = "hello world"

test if two numbers are equal
test $number -eq 3

test if $filename exists and is a regular file
test -f $filename

test if $filename exists and is a regular file AND is not executable
test -f $filename -a ! -x $filename

test if $number is greater than 7
test $number -gt 7