Skip to content

Arithmetic operation in Bash

homepage-banner

1:$(( ))

2:$[ ]

3:expr

C=`expr $A + $B`

4:bc

#!/bin/bash
x=1
y=2
echo $(( x + y ))
echo $[ $x + $y ]
echo `expr $x + $y`
let z=$x+$y
echo $z

bc <<< "scale=3; 11/15"

5:let

let C=$A+$B

Back to Table of Contents

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.com, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No personal information is collected.
Feedback