1830481 Members
2610 Online
110005 Solutions
New Discussion

Odd problem with "let"

 
SOLVED
Go to solution
Simone Benzi_1
Frequent Advisor

Odd problem with "let"

Hello everybody,

I'm facing to the following problem in my last shell script:

Everybody knows that:

600426*4096=2459344896

...everybody but let...

#let MEM_FREE=600426*4096
#echo $MEM_FREE
-1835622400

Is there any limitation with let? (i.e. 2147483648 = 2Gb)
How can assign the correct value to MEM_FREE?

Thanks a lot for your help!

Simone
5 REPLIES 5
David_246
Trusted Contributor

Re: Odd problem with "let"

Looks like the max is :

$ echo `expr 524287 * 4096`
2147479552

There is not a higher value possible. Don't know the cause. Maybe this number does anything to someone.

Regs David
@yourservice
RAC_1
Honored Contributor
Solution

Re: Odd problem with "let"

I know this can be done as follows with bc, but I need some classes on shell scripting.
export MEM_FREE=`echo "600426*4096"|bc`

echo $MEM_FREE
There is no substitute to HARDWORK
Steve Steel
Honored Contributor

Re: Odd problem with "let"

Hi

For big numbers use bc in your script

You are hitting a known problem;

#!/usr/bin/sh
#You could use the 'two way pipe' to the program to do all your math operations,
like this:
# This starts bc with a two-way pipe
bc |&
# print -p writes to the pipe
print -p scale=4
print -p 3/4
# read -p reads from the pipe
read -p myvar
echo $myvar


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Jeroen Peereboom
Honored Contributor

Re: Odd problem with "let"

Simone,

check this link: http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=19128

There is indeed a limitation.
The link also contains suggestions.

JP.
Simone Benzi_1
Frequent Advisor

Re: Odd problem with "let"

Thank you everybody!
I'll use "bc" in my scripts.

Points assigned...


Simone