Logic Expressions

Learn what boolean expressions are and how they work.

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 consider Boolean expressions using an example. For simplicity, the example is not related to the find utility or Bash. Let’s imagine that we are programming a robot for a warehouse. Its job is to move boxes from point A to point B. We can write the following straightforward algorithm for the robot:

  1. Move to point A.
  2. Pick up the box at point A.
  3. Move to point B.
  4. Put the box at point B.

Get hands-on with 1400+ tech skills courses.