From the course: Learning Bash Scripting
Unlock this course with a free trial
Join today to access over 24,500 courses taught by industry experts.
Working with numbers - Bash Tutorial
From the course: Learning Bash Scripting
Working with numbers
- When we work with numbers in Bash we have two tools at our disposal, arithmetic expansion and arithmetic evaluation. Arithmetic expansion lets us use literal numbers or variables and perform mathematical operations on them. Giving us a result we can display or assign to a variable. Arithmetic evaluation makes changes to the value of an existing variable. Bash supports six basic arithmetic operators, addition with a plus, subtraction with a minus, multiplication with a single asterisk, division with a forward slash, modulo with a percent sign and exponentiation with double asterisks. And it's important to point out Bash can only do calculations with integers. We'll explore this limitation more in a little while. Let's take a moment to use arithmetic expansion here at the Bash prompt. I'll write echo, dollar sign, two opening parentheses, four plus four and two closing parentheses, that's eight. I'll write a few more of these…
Contents
-
-
-
-
Understanding Bash script syntax5m 18s
-
(Locked)
Choosing a text editor for Bash scripting1m 33s
-
(Locked)
Displaying text with "echo"4m 26s
-
(Locked)
Working with variables5m 21s
-
(Locked)
Working with numbers8m 44s
-
(Locked)
Comparing values with test4m 59s
-
(Locked)
Comparing values with extended test3m 34s
-
(Locked)
Formatting and styling text output8m 13s
-
(Locked)
Formatting output with printf5m 6s
-
(Locked)
Working with arrays4m 25s
-
(Locked)
Challenge: Make a script that generates a system report1m 1s
-
(Locked)
Solution: Make a script that generates a system report1m 26s
-
-
-
-
-