The following table lists the operators that are used in expressions.
Table A–2 List of Expression Operators
Operator Symbol |
Operator Name |
---|---|
! |
C-style logical not |
= |
Wildcard pattern match |
=~ |
Regular expression match |
!~ |
Regular expression mismatch |
+ |
Addition or unary plus |
- |
Subtraction or unary minus |
. |
String concatenation |
defined |
Value is defined |
-d |
Directory exists |
-e |
File or directory exists |
-f |
File exists |
-l |
Symbolic link exists |
-r |
File is readable |
-s |
File size |
-U |
URI maps to accessible file or directory |
< |
Numeric less than |
<= |
Numeric less than or equal to |
> |
Numeric greater than |
>= |
Numeric greater than or equal to |
lt |
String less than |
le |
String less than or equal to |
gt |
String greater than |
ge |
String greater than or equal to |
== |
Numeric equal |
!= |
Numeric not equal |
eq |
String equal |
ne |
String not equal |
^ |
C-style exclusive or |
&& |
C-style logical and |
|| |
C-style logical or |
not |
Logical not |
and |
Logical and |
or |
Logical or |
xor |
Logical exclusive or |
The following table lists the precedence of operators within expressions from highest to lowest precedence.
Table A–3 Operator Precedence
Symbol |
Operands |
Associativity |
Description |
---|---|---|---|
( ), [ ] |
0 |
Left to right |
Parentheses |
!, unary +, unary - |
1 |
Right to left |
Sign operators |
=, =~, !~ |
2 |
Non-associative |
Pattern matching operators |
+, -, . |
2 |
Non-associative |
Additive operators |
defined, -d, -f, -l, -r, -s, -U |
1 |
Right to left |
Named operators |
<, lt, <=, le, >, gt, >=, ge |
2 |
Non-associative |
Relational operators |
==, eq, !=, ne |
2 |
Non-associative |
Equality operators |
^ |
2 |
Left to right |
C-style exclusive or operator |
&& |
2 |
Left to right |
C-style logical and operator |
|| |
2 |
Left to right |
C-style logical or operator |
not |
1 |
Right to left |
Logical not operator |
and |
2 |
Left to right |
Logical and operator |
or, xor |
2 |
Left to right |
Logical or operators |
The numeric operators (<, <=, >, >=, ==, and !=) are intended to operate on numbers and not strings. To facilitate comparing numbers, dates, and timestamps, the numeric operators ignore any white space, colons, slashes, and commas in their arguments. Dashes after the first digit are also ignored.
It is generally incorrect to use the numeric operators on non-numeric values.
For example, the following expression evaluates to true:
# The following expression evaluates to true because both # "foo" and "bar" are numerically equivalent to 0 ("foo" == "bar")