Bash Operators
Understanding Bash Operators
This section provides an overview of operators used in Bash scripting, including comparison, string, arithmetic, logical, and file test operators.
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 Comparison Operators
=: Equal to!=: Not equal to<: Less than, in ASCII alphabetical order>: Greater than, in ASCII alphabetical order
Arithmetic Operators
+: Addition-: Subtraction*: Multiplication/: Division%: Modulus (remainder of division)- For exponentiation, use external tools like
bcorawk.
Logical Operators
&&: Logical AND||: Logical OR!: Logical NOT
File Test Operators
-e: Checks if a file exists-d: Checks if a directory exists-f: Checks if a file is a regular file-s: Checks if a file is not empty