Bash - Arithmetic Expression (())

1 - About

arithmetic in bash

3 - Evaluation

An expression is evaluated according to the following rules

If the value of the expression is:

  • non-zero, the return status is 0;
  • otherwise the return status is 1.

4 - Management

4.1 - Variable

If the variable has its integer attribute set (see Bash - Declare (Variable declaration and attribute)), then value is evaluated as an arithmetic expression even if the $((...)) expansion is not used.

4.2 - Expansion (Execution)

  • Bash - Let (Arithmetic expression evaluation)
  • ((arithmetic_expression)) see Shell - Compound Commands
  • $((arithmetic_expression))

4.3 - Operator

  • In the context where an assignment statement is assigning a value to a

shell variable, the += operator can be used to append to or add to the variable’s previous value. When += is applied to a vari- able for which the integer attribute has been set, value is evaluated as an arithmetic expression and added to the variable’s current value, which is also evaluated.

4.4 - Comparison

if (( a > b )); then

if [ "$a" -gt "$b" ]; then

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap