Bash - Arithmetic Expression

Bash Liste Des Attaques Ovh


arithmetic in bash

part of compound expression .


  • Counter
(( counter + 1))
  • Simple addition
echo One plus One is $((1+1))
echo One plus One is 2


(( arithmetic expression ))
# or to capture the output
# or
let arithmetic_expression [arithmetic_expression, ...]

where let is the let command

If the value of the expression is:

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



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.


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 variable 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.


  • As number
if (( a > b )); then
if [ "$a" -gt "$b" ]; then

Discover More
Bash Liste Des Attaques Ovh
Bash - (Environment) Variable

A variable is a parameters referenced by a name. parameter A variable has: a value and zero or more attributes (such as integer, ...). Attributes are assigned using the declare builtin command....
Bash Liste Des Attaques Ovh
Bash - Case

The case control statement execute commands based on regular expression pattern matching. Initscript example: Selectively execute COMMANDS based upon WORD matching glob PATTERN. The | is used to...
Bash Liste Des Attaques Ovh
Bash - Declare (Variable declaration and attribute)

Declare variables and/or give them attributes. where: names: If no names are given then display the values of variables. p will display the attributes and values of each name. When -p is used,...
Bash Liste Des Attaques Ovh
Bash - Dollar Character

The $ character introduces: , , or arithmetic expansion.
Bash Liste Des Attaques Ovh
Bash - Expansion

This article is expansion in Bash. An expansion is the replacement of a special token in your code by the result of the expansion during code execution. It's performed on the command line after it has...
Bash Liste Des Attaques Ovh
Bash - Here Documents

in Bash. Here document in Bash is implemented through redirection. A redirection instructs the shell to read input from the current source until a line containing only word (with no trailing blanks)...
Bash Liste Des Attaques Ovh
Bash - Integer

This article is the management of integer in bash. See See 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"...
Bash Liste Des Attaques Ovh
Bash - Let (Arithmetic expression evaluation)

Let is a builtin command that evaluate an arithmetic expression. where: Each arg is an arithmetic expression to be evaluated If: the last arg evaluates to 0, let returns 1; 0 is returned...
Bash Liste Des Attaques Ovh
Bash - Parameter Expansion ${

Parameter expansion are patterns applied to the parameters that have different results. Same as ?? See also: The value of parameter is substituted where: the braces are optional. They served...
Bash Liste Des Attaques Ovh
How to create a counter in Bash?

This article shows you how to create a integer counter in Bash With the integer comparison operator and an arithmetic operation

Share this page:
Follow us:
Task Runner