# 算術

##### let
``````#!/usr/bin/env bash

let NUMBER1=10
let NUMBER2=3

# Subtraction => - operator
let SUB=\$NUMBER1-\$NUMBER2
echo "Subtraction of two numbers : \${SUB}"

# Multiply => * operator
let MUL=\$NUMBER1*\$NUMBER2
echo "Multiply two numbers : \${MUL}"

# Divide => / operator
let DIV=\$NUMBER1/\$NUMBER2
echo "Division of two numbers : \${DIV}"

# Remainder => % operator
let REM=\$NUMBER1%\$NUMBER2
echo "Remainder of two numbers : \${REM}"

# Exponent => ** operator
let EXPO=\$NUMBER1**\$NUMBER2
echo "Exponent of two numbers : \${EXPO}"

# post increment and post decrement operations
let variable++
let variable--``````
##### Double Brackets
``````((NUMBER2++)
((NUMBER1--))

(( NUMBER2 = NUMBER2 + 10 ))
(( NUMBER2 += 10 )) # Shorthand``````
##### expr
``````expr 10 + 3 # Addition
expr 10 - 3 # Subtraction
expr 10 * 3 # Multiply
expr 10 / 3 # Divide
expr 10 % 3 # Remainder``````
##### bc
``````# Add
\$ echo "10 + 100" | bc
=> 110

\$ echo "10.15 + 11.20" | bc
21.35

# Subtract
\$ echo "100 - 25" | bc
=> 75

\$ echo "100 - 25.5" | bc
=> 74.5

# Multiply
\$ echo "10 * 5" | bc
=> 50

\$ echo "10.10 * 4" | bc
=> 40.40

# without scale
echo "10.10 / 4" | bc
=> 2

# with scale
echo "scale=2;10.10 / 4" | bc
=> 2.52

\$ echo "2.2^4" | bc
=> 23.4``````
##### awk
``````\$ awk "BEGIN {print 23 * 4.5 }"
=> 103.5

\$ awk "BEGIN{print int(10.111) }"
=> 10

\$ awk "BEGIN{print sqrt(10) }"
=> 3.16228

# Since this is a CSV file, I am setting the field separator to(-F “,”).
# Here the entire second column is first added and divided by the NR(number of records).
\$ awk -F "," '{sum+=\$2} END { print "average value from column 2 = ",sum/NR}' data.csv``````