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

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…

Contents