We can use two ways:

  • variable=$((var1 + var2 + var3*2))
  • let variable=var1+var2+var3*2

 

Attantion! NO SPACES around “=” character.  if you write “variable = ….” then bash will try to execute command “variable”.

 

Assignment operators in bash:

  • = simple assignment
  • *= multiplication (a=a*b)
  • /= division (a=a/b)
  • %= remainder from integer division (a=a%b)
  • += addition (a=a+b)
  • -= subtraction (a=a-b)