test(1) - SerenityOS man pages

#Name

test - check files and compare values

#Synopsis

$ test expression
$ test
$ [ expression ]
$ [ ]

#Description

test takes a given expression and sets the exit code according to its truthiness, 0 if true, 1 if false. An omitted expression defaults to false, and an unexpected error causes an exit code of 126.

If test is invoked as [, a trailing ] is required after the expression.

#Expressions

The expression can take any of the following forms:

#Grouping

#Boolean operations

#String comparison

#Integer comparison

#File comparison

#File type checks

#File permission checks

Except for -h/-L, all file checks dereference symbolic links.

NOTE: Your shell might have a builtin named 'test' and/or '[', please refer to your shell's documentation for further details.

#Options

None.

#Examples

# Conditionally do something based on the value of a variable
$ /bin/test "$foo" = bar && echo foo is bar
# Check some numbers
$ /bin/test \( 10 -gt 20 \) -o \( ! 10 -ne 10 \) && echo "magic numbers!"

#See Also