September 2018
Beginner
186 pages
4h 30m
English
Bash supports simple integer (whole number) arithmetic operations with its arithmetic expressions. The syntax for expanding these is a set of double parentheses after the usual $ expansion sign:
$ num_a=3 $ num_b=2 $ printf 'The sum of the two numbers is: %u\n' "$((num_a + num_b))" The sum of the two numbers is: 5
Notice in the preceding expression, "$((num_a + num_b))", we did not have to use the $ prefix to expand the num_a and num_b variables names. Assignments to other variables can be performed in the same way:
$ diff="$((num_a - num_b))" $ printf 'The difference of the two numbers is: %u\n' "$diff" The difference of the two numbers is: 1
We can do many different kinds of operations with these expressions, using both ...
Read now
Unlock full access