Search⌘ K
AI Features

Advanced Features of the [[ Operator

Understand how to use advanced features of the [[ operator in Bash, including logical AND, OR, NOT, grouping expressions, and file attribute checks. Learn to apply these in conditional statements to create more precise and powerful scripts.

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"
!
...