In Bash, when writing shell scripts then we need to use test operators to compare integer values, strings, and logical tests and file tests, etc. So here I am sharing the list of all bash shell operators in text and in picture format, which is downloadable.
Bash Shell Test Operators Cheat Sheet
Integer Comparisons | Function |
---|
-gt | Greater than |
-lt | Less than |
-ge | Greater than or equal to |
-le | Less than or equal to |
-eq | Equal to |
-ne | Not equal to |
String Comparisons | Functions |
---|
-z | Test for empty string |
= | Test for equality of strings |
!= | Test for inequality of strings |
Logical Operators | Function |
---|
-a | Logical AND |
-o | Logical OR |
! | Logical NOT |
File Test Operators | Function |
---|
-f | File exists and is a regular file |
-s | File is not empty |
-r | File is readable |
-w | File can be written to and modified |
-x | File is executable |
-d | Filename is a directory name |
Download the Bash Shell Test Operators Cheat Sheet in Picture format:
See also: