calculation in a bash script

Haven't been scripting under unix for a long time... many years
Can someone remind me how to calculate 2 + 3 and store the result in a variable.
Must be something with eval and/or bc, but can't find what it is anymore
LVL 28
lesouefAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
JulieBouillonConnect With a Mentor Commented:
Hi,

SUM=$((2+3))
echo $SUM
0
 
lesouefAuthor Commented:
works. just wondering why we need double (())...

another point if I wanna check if $sum < 10, what's the right syntax? if I use <, it looks for a file to redirect. if I use LEQ, it does not understand...
since i've been javascript, it has confused me more! and the man is really on outdated tool. so am I probably!
0
 
JulieBouillonCommented:
You need $(()) because using $(command) is the same as using `command`

$sum < 10
$sum -lt 10

Just a few more operators:
lt -> less than
gt -> greater than
eq -> equal
ne -> equal
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
lesouefAuthor Commented:
strange, this was I had done in between.
when using
 if [ $sum < 10 ] ; then etc....
I get in insult something like file not found (10)??
0
 
JulieBouillonCommented:
It should have beem more explicit:
it is not -> $sum < 10
but -> $sum -lt 10
0
 
lesouefAuthor Commented:
ok, works. many thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.