Solved

calculation in a bash script

Posted on 2006-06-29
6
3,856 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 100 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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction How to create multiboot configuration with XP\Vista and Windows 7 on it? And most important question - how to do this correctly so not to have any kind of nightmares we get when system gets screwed? First of all one should realize t…
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
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.

691 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