From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Using arithmetic operators - Linux Tutorial
From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation
Using arithmetic operators
- [Instructor] Bash has lots of arithmetic operators. I like to use the double parens. And then I think it's pretty natural, especially since I've been a C programmer for a long time, so a lot of it looks like C. If you're a C programmer, then I think you'll find it comfortable too. We see here lots of operators. We have increment and decrement, we have bitwise, operators, we have exponentiation, multiplication, division, we've got shifting, we've got equality, we've got logical operations, ands and ors. We've got assignment operations that combine other operators. So there's a lot you can do. But the usual kind of straightforward stuff I think is pretty easy. The n++ adds one to n. So n starts out at five, then it would be six. And in the second example, we have a logical or, so we got if n is greater than four or n equals zero. And here we have more sophisticated operations. We have n = 2q + 5, and then we have y = n ^ 4. Hat, what is that? Well, that one's a little bit tricky…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
The typeset and declare commands for variables and arrays5m 59s
-
(Locked)
Looping with while sequences and reading input6m 12s
-
(Locked)
Looping with for, the seq command, and backticks8m 3s
-
(Locked)
Defining functions and using return and exit4m 17s
-
(Locked)
Using file descriptors, file redirection, and pipes7m 23s
-
(Locked)
Here documents3m 54s
-
(Locked)
Open and close file descriptors5m 22s
-
(Locked)
Control-flow if-then-else with the test command4m 42s
-
(Locked)
Case statements3m 45s
-
(Locked)
Using arithmetic operators3m 26s
-
(Locked)
Challenge: Variables in functions, loops, and arithmetic2m 46s
-
(Locked)
Solution: Variables in functions, loops, and arithmetic2m 42s
-
-
-
-