Bash Script Operator Reference
This page contains a reference of helpful operators that can be used in Bash scripts.
You can learn more about (most) of these operators in the article on Bash operators.
Arithmetic Operators
+
(Addition)-
(Subtraction)*
(Multiplication)/
(Division)%
(Modulus)
Comparison Operators
-eq
(Equal to)-ne
(Not equal to)-lt
(Less than)-le
(Less than or equal to)-gt
(Greater than)-ge
(Greater than or equal to)
String Operators
=
(Equal to)!=
(Not equal to)-z
(Empty string)-n
(Non-empty string)>
(Greater than, in ASCII order)<
(Less than, in ASCII order)
Logical Operators
!
(Logical NOT)&&
(Logical AND)||
(Logical OR)
File Test Operators
-e
(File exists)-f
(File is a regular file)-d
(File is a directory)-r
(File is readable)-w
(File is writable)-x
(File is executable)
Assignment Operators
=
(Simple assignment)+=
(Add and assign to variable)- -= (Subtract and assign)
- *= (Multiply and assign)
- /= (Divide and assign)
Miscellaneous Operators
:
(Null command, does nothing, used for syntax purposes).
(Source a script, execute commands in the current shell)
These operators can be combined with conditional statements (if
, elif
, else
) and loops (for
, while
, until
) to build complex scripts for various purposes.