Solved

calculation in a bash script

Posted on 2006-06-29
6
3,838 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many people tend to confuse the function of a virus with the one of adware, this misunderstanding of the basic of what each software is and how it operates causes users and organizations to take the wrong security measures that would protect them ag…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now