Skip to content

Arithmetic operation in Bash

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

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