Table of Contents

About

This article is about the management of integer in bash.

Example

See How to create a counter in Bash?

Management

From float to int

averageCpu=20.34
averageCpuInt=$( printf "%.0f" "$averageCpu" )
echo $averageCpuInt;

Operation

See Bash - Arithmetic Expression

Comparison

The ordinal comparison operator in Bash are:

Double Bracket operator Single Bracket Operator Example
-lt -lt [[ 8 -lt 9 ]] && echo "8 is less than 9"
-ge -ge [[ 3 -ge 3 ]] && echo "3 is greater than or equal to 3"
-gt -gt [[ 5 -gt 10 ]] || echo "5 is greater than than 10"
-le -le [[ 3 -le 8 ]] && echo "3 is less than or equal to 8"
-eq -eq [[ 5 -eq 05 ]] && echo "5 equals 05"
-ne -ne [[ 6 -ne 20 ]] && echo "6 is not equal to 20"