Advanced Features of the [[ Operator
Learn features of the [[ operator besides string comparison.
We'll cover the following...
Logical operations in the [[
operator
We can use logical operations AND, OR, and NOT in the [[ operator. They combine several boolean expressions into a single condition. The following table explains how they work.
Operation | Description | Example |
---|---|---|
&& |
Logical AND | [[ -n "$var" && "$var" < "abc" ]] && echo "The string is not empty and it is smaller than \"abc\"" |
|| |
Logical OR | [[ "abc" < "$var" \|\| -z "$var" ]] && echo "The string is larger than \"abc\" or it is empty" |
! |