1748059 Members
4957 Online
108758 Solutions
New Discussion юеВ

Re: command 'let'

 
SOLVED
Go to solution
Jannik
Honored Contributor

command 'let'

The command let don't work with large numbers, is there another command for large numbers.

#!/usr/bin/ksh
ADD=0

for i in $(vxprint -Aht | grep 'v ' | awk '{print $6}')
do
let ADD=$i+$ADD
echo $ADD
done
jaton
9 REPLIES 9
Victor Fridyev
Honored Contributor

Re: command 'let'

Try this:
ADD=$(( $i + $ADD))
HTH
Entities are not to be multiplied beyond necessity - RTFM
Jannik
Honored Contributor

Re: command 'let'

output:
...
2125725696
-1477181440
515112960
...

does not work (sorry)!
jaton
Geoff Wild
Honored Contributor

Re: command 'let'

Try it with awk


TOTAL=`$(vxprint -Aht | grep 'v ' | awk '{print $6}') | awk 'BEGIN {tot=0} $2 == "total" {tot=tot+$1} END`

Or something like that - don't have vx on my servers so I can't test it...

But I do something like this:

ttldisk=`df -t -l | awk 'BEGIN {tot=0} $2 == "total" {tot=tot+$1} END {print (tot*512)/1024/1024/1024}'`

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Victor Fridyev
Honored Contributor

Re: command 'let'

Try this one:
argus:/# typeset -i T
argus:/# typeset -i P
argus:/# T=2125725696
argus:/# echo $T
2125725696
argus:/# P=-1477181440
argus:/# echo $P
-1477181440
argus:/# T=$T+$P; echo $T
648544256
Entities are not to be multiplied beyond necessity - RTFM
Franky_1
Respected Contributor
Solution

Re: command 'let'

Hi Jannik,

try the following (for example):

A=2457886
B=7756737
C=0
for i in A,B
do
C=`echo $A + $B|bc`
done
echo $C

The "bc" command should do the trick

Regards

Franky
Don't worry be happy
Bill Hassell
Honored Contributor

Re: command 'let'

All the shells have limited math capability. Integer only and 32 bit numbers. As mentioned, awk and bc are the workarounds for extended math. They have lots of functions available too.


Bill Hassell, sysadmin
Franky_1
Respected Contributor

Re: command 'let'

Hi Jannik,

if someone of us could help you, would you mind assining points ?

Cheers

Franky
Don't worry be happy
Jannik
Honored Contributor

Re: command 'let'

bc command worked:
10240000
13312000
15933440
16138240
16449536
20643840
24838144
27910144
29106176
33816576
44302336
55836672
81002496
206831616
238288896
290717696
306446336
327417856
348389376
364118016
374603776
385089536
395575296
432275456
484704256
537133056
589561856
594804736
605290496
919863296
1129578496
1161035776
1192493056
1223950336
1244921856
2083782656
2104754176
2125725696
2817785856
4810080256
4852023296
4966567936
4971810816
4988588032
4993830912
5203546112
5207740416
5215080448

Sorry for the late points!

tnx
jaton
Dennis Handly
Acclaimed Contributor

Re: command 'let'

64 bit integers should be supported in the latest ksh but not the Posix shell.