The declare -i command in bash scripting is used to declare a variable as an integer. This allows the variable to be treated as a numeric value, enabling arithmetic operations to be performed on it.
For example:
declare -i number=5
declare -i result=number*2
echo $result # This will output 10
In this example, number is declared as an integer, and when multiplied by 2, the result is calculated correctly as an integer. This is particularly useful for counters, calculations, and any numeric processing in your scripts.
