Basic Linux Tutorial
Computer Tutorial

The test Command



The test Command

The test command is used to evaluate expressions and generate a return code. It takes arguments that form logical expressions and evaluates the expressions. The test command writes nothing to standard output. You must display the value of the return code to determine the result of the test command. The return code will be set to 0 if the expression evaluates to true, and the return code will be set to 1 if the expression evaluates to false. The test command is initially presented alone so that you can display the return codes. But it is most commonly used with the if and while constructs to provide conditional flow control.

The test command can also be invoked as [ expression ]. This is intended to assist readability, especially when implementing numerical or string tests.

Synopsis :

test   expression   or   [ expression ]


The test command can evaluate the condition of :
• Integers
• Strings
• Files