Linux Bash Operators Like Assignment, Plus, Calculation

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-bash-operators-like-assignment-plus-calculation/
PINTEREST
PINTEREST
INSTAGRAM
  1. Introduction To Linux Bash Programming
  2. Linux Bash Directories and Files
  3. Linux Bash Environment Variables
  4. Linux Bash Variables
  5. Linux Bash Functions
  6. Linux Bash If Else Conditionals
  7. Linux Bash Create and Run Script Files
  8. Linux Bash Operators
  9. Linux Bash Arrays
  10. Linux Bash Input, Output and Redirection
  11. Linux Bash History
  12. Linux Bash Alias
  13. Linux Bash .bashrc File
  14. Linux Bash Debugging

We can store different type of values in the variables. But just storing values is generally not enough and we need to make some operations with them. In this tutorial we will look different type of operators which will work with variables.

Assignment

The most used operator and generally underestimated its power. Variable assignment is made with =. By the way be aware that you do not confuse assignment operator with test operator which is the same =.

Let Operator

In bash scripting to make mathematical calculations and use operators let expression is used. let expression makes afterward expressions mathematically calculated. Look example below

Plus

To make sum operations + is used as expected but be aware of that let should be used.

Plus Equal

Plus equal is similar to plus but makes operations easy when one of the sum parameters are same for the result

Minus

Usage usage of the minus operator is the same with plus operator. As you know just the effect is different

LEARN MORE  C Operators - Logical, Arithmetic, Relational

Minus Equal

Plus equal is similar to plus but makes operations easy when one of the sum parameters are same for the result

Multiplication

You can find the multiplication operation below

Simple, isn’t is?

Division

You can find the division operation below

Exponentiation

Generally this type of operations are not required in bash scripting but to be aware of this operator we make simple example

Modulo

To get remainder of a division module is used. For example what will be the remainder after 5/3. We can use following code for this operation. As you will see below we have new keyword named expr

Bit-wise

Decimal numbers can be expressed in binary format. So if we need to shift the binary values of a decimal Bit-wise operator can be used.

In this example we have rotated binary for 2 times. Before the rotation binary value was like 0000010. After the rotation it is like 0001000 where its decimal value is 8. We have used = to make assignment easy.

Bit-wise operations can be done in reverse order like >>.

LEARN MORE  C Variables and Definition

And

Logical operations are important for a programming language. Bash have full support for logical operations like AND.

  1. Introduction To Linux Bash Programming
  2. Linux Bash Directories and Files
  3. Linux Bash Environment Variables
  4. Linux Bash Variables
  5. Linux Bash Functions
  6. Linux Bash If Else Conditionals
  7. Linux Bash Create and Run Script Files
  8. Linux Bash Operators
  9. Linux Bash Arrays
  10. Linux Bash Input, Output and Redirection
  11. Linux Bash History
  12. Linux Bash Alias
  13. Linux Bash .bashrc File
  14. Linux Bash Debugging
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-bash-operators-like-assignment-plus-calculation/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)