Logical Operations
Learn how logical operations can help us compare numbers.
We'll cover the following
Comparison symbols
The [[
operator is inconvenient for comparing integers in the if
statement. This operator uses two-letter abbreviations for expressing the relations between numbers. For example, the -gt
abbreviation means greater. When we apply the ((
operator instead, we can use the usual comparison symbols instead. These symbols are >
, <
, and =
.
Here is an example. Let’s suppose that we want to compare a variable with the number 5. The following if
construction does so:
if ((var < 5))
then
echo "The variable is less than 5"
fi
We can run the codes discussed in this lesson by modifying the
script.sh
. Click on the “Run” button and then execute the file.
Get hands-on with 1400+ tech skills courses.