# bash - do calulations / math / addition / subtraction in bash

Posted by rolf on Thursday, 5 March 2015

1. Remove leading zeros

num=0004; num=$(expr $num + 0) echo $num; # output: 4

2. subtract integers

num=3; subtract=50; numNew=$(( $num - $subtract)); echo $numNew; #result: -47

3. divide

num_half=$(expr $num / 2)

## Add new comment