String Operators

If we compare strings, then we know what we would like to have in the corresponding value.

OperatorDescription
==is equal to
!=is not equal to
<is less than in ASCII alphabetical order
>is greater than in ASCII alphabetical order
-zif the string is empty (null)
-nif the string is not null

Integer Operators

Comparing integer numbers can be very useful for us if we know what values we want to compare. Accordingly, we define the next steps and commands how the script should handle the corresponding value.

OperatorDescription
-eqis equal to
-neis not equal to
-ltis less than
-leis less than or equal to
-gtis greater than
-geis greater than or equal to

File Operators

The file operators are useful if we want to find out specific permissions or if they exist.

OperatorDescription
-eif the file exist
-ftests if it is a file
-dtests if it is a directory
-Ltests if it is if a symbolic link
-Nchecks if the file was modified after it was last read
-Oif the current user owns the file
-Gif the file’s group id matches the current user’s
-stests if the file has a size greater than 0
-rtests if the file has read permission
-wtests if the file has write permission
-xtests if the file has execute permission

Logical Operators

With logical operators, we can define several conditions within one. This means that all the conditions we define must match before the corresponding code can be executed.

OperatorDescription
!logical negotation NOT
&&logical AND
|logical OR