Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: evaluate a mathematical term?

echo 3+3 

How can I evaluate such expressions in Bash, in this case to 6?

like image 301
hhh Avatar asked Mar 31 '10 10:03

hhh


People also ask

How do you evaluate in math in bash?

The recommended way to evaluate arithmetic expressions with integers in Bash is to use the Arithmetic Expansion capability of the shell. The builtin shell expansion allows you to use the parentheses ((...)) to do math calculations. The format for the Bash arithmetic expansion is $(( arithmetic expression )) .

Can bash script do math?

Math and arithmetic operations are essential in Bash scripting. Various automation tasks require basic arithmetic operations, such as converting the CPU temperature to Fahrenheit. Implementing math operations in Bash is simple and very easy to learn.


1 Answers

echo $(( 3+3 )) 
like image 94
Marcelo Cantos Avatar answered Sep 29 '22 04:09

Marcelo Cantos