?
Solved

calculation in a bash script

Posted on 2006-06-29
6
Medium Priority
?
3,857 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:lesouef
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 4

Accepted Solution

by:
JulieBouillon earned 400 total points
ID: 17009633
Hi,

SUM=$((2+3))
echo $SUM
0
 
LVL 28

Author Comment

by:lesouef
ID: 17010753
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
 
LVL 4

Expert Comment

by:JulieBouillon
ID: 17012175
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
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 
LVL 28

Author Comment

by:lesouef
ID: 17013314
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
 
LVL 4

Expert Comment

by:JulieBouillon
ID: 17013798
It should have beem more explicit:
it is not -> $sum < 10
but -> $sum -lt 10
0
 
LVL 28

Author Comment

by:lesouef
ID: 17015857
ok, works. many thanks.
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I don't know if many of you have made the great mistake of using the Cisco Thin Client model with the management software VXC. If you have then you are probably more then familiar with the incredibly clunky interface, the numerous work arounds, and …
Sometimes a user will call me frantically, explaining that something has gone wrong and they have tried everything (read - they have messed it up more and now need someone to clean up) and it still does no good, can I help them?!  Usually the standa…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question