Search⌘ K
AI Features

Logic Expressions

Explore how boolean expressions and logical operators such as AND, OR, NOT, XOR, equivalence, and non-equivalence are used in Bash programming. Understand how these expressions control conditional statements, enabling complex decision-making like avoiding obstacles in automation tasks. This lesson helps you grasp fundamental logic needed to write effective Bash scripts.

The search conditions of the find utility are boolean expressions. A boolean expression is a programming language statement. It produces a boolean value when evaluated that equals either true or false.

The find condition is a statement of the utility’s language. It produces the true value if the found object meets its requirement. Otherwise, the condition produces false. If there are several conditions in the find call, they make a single compound boolean expression.

Logical operators

When we considered the binary numeral system, we already were introduced to boolean algebra. This section of mathematics studies logical operators. They differ from the arithmetic operations: addition, subtraction, multiplication, and division.

We can apply a logical operator to boolean values or expressions. Using an arithmetic operation doesn’t make sense in this case. Addition or subtraction is trivial for boolean values. It yields nothing. When we apply a logical operator, we get a condition with strict evaluation rules. This way, we previously wrote search conditions for the find utility. When we combine several conditions, we get a program with complex behavior.

Operand

An operand is an object of a logical operator. Boolean values and expressions can be operands.

Programming a robot

Let’s ...