#!/bin/bash# Works as stringexpr'10 + 30'# Works as stringexpr 10+30
#Perform the additionexpr 10 + 30
#Find out the remainder valueexpr 30 % 9
#Using expr with backtickmyVal1=`expr 30 / 10`echo$myVal1#Using expr within command substitutemyVal2=$(expr 30 - 10 )echo$myVal2
#!/bin/bash# Multiplying 9 by 8let val1=9*3
echo$val1# Dividing 8 by 3let"val2 = 8 / 3"echo$val2# Subtracting 3 from 9let val3=9-3
echo$val3# Applying incrementlet val4=7
let val4++
echo$val4# Using argument value in arithmetic operationlet"val5=50+$1"echo$val5
#!/bin/bash# Calculate the mathematical expressionval1=$((10*5+15))echo$val1# Using post or pre increment/decrement operator((val1++))echo$val1val2=41
((--val2))echo$val2# Using shorthand operator(( val2 += 60 ))echo$val2# Dividing 40 by 6(( val3 = 40/6 ))echo$val3
예제.4 - Using ‘bc’ command for float or double numbers
bc(basic calculator)는 리눅스 기본계산기 입니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash# Dividing 55 by 3 with bc onlyecho"55/3" | bc
# Dividing 55 by 3 with bc and -l optionecho"55/3" | bc -l# Dividing 55 by 3 with bc and scale valueecho"scale=2; 55/3" | bc
#거듭제곱echo"2^10" | bc