Bash Arithmetic Operations
You can perform arithmetic operations on numeric values in bash scripts. You can find many options to perform arithmetic operations on bash shell but the below example will provide you the simplest way.
Syntax:
Bash Arithmetic Operations Example:
For example, take an input of two numeric values and perform all 5 basic arithmetic operations like below:
Increment and Decrement Operator:
Bash also used increment (++) and decrement (–) operators. Both use in two types pre-increment/post-increment and pre-decrement/post-decrement.
Similarly, try pre-decrement and post-decrement operators in the bash shell.
1 2 3 4 5 6 7 | ## Post-decrement example $ var=10 $ echo $((var--)) ## First print 10 then decrease value by 1 ## Pre-decrement example $ var=10 $ echo $((--var)) ## First decrease value by 1 then print 9 |
0 Comments
CAN FEEDBACK
Emoji