Re: command 'let' (210 Views)
Reply
Honored Contributor
Jannik
Posts: 490
Registered: ‎01-19-2003
Message 1 of 10 (210 Views)
Accepted Solution

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
Please use plain text.
Honored Contributor
Victor Fridyev
Posts: 937
Registered: ‎07-01-1998
Message 2 of 10 (210 Views)

Re: command 'let'

Try this:
ADD=$(( $i + $ADD))
HTH
Entities are not to be multiplied beyond necessity - RTFM
Please use plain text.
Honored Contributor
Jannik
Posts: 490
Registered: ‎01-19-2003
Message 3 of 10 (210 Views)

Re: command 'let'

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

does not work (sorry)!
Please use plain text.
Honored Contributor
Geoff Wild
Posts: 7,168
Registered: ‎06-04-2001
Message 4 of 10 (210 Views)

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.
Please use plain text.
Honored Contributor
Victor Fridyev
Posts: 937
Registered: ‎07-01-1998
Message 5 of 10 (210 Views)

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
Please use plain text.
Respected Contributor
Franky_1
Posts: 322
Registered: ‎01-14-2001
Message 6 of 10 (210 Views)

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
Please use plain text.
Honored Contributor
Bill Hassell
Posts: 14,178
Registered: ‎05-29-2000
Message 7 of 10 (210 Views)

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.
Please use plain text.
Respected Contributor
Franky_1
Posts: 322
Registered: ‎01-14-2001
Message 8 of 10 (210 Views)

Re: command 'let'

Hi Jannik,

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

Cheers

Franky
Don't worry be happy
Please use plain text.
Honored Contributor
Jannik
Posts: 490
Registered: ‎01-19-2003
Message 9 of 10 (210 Views)

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
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,746
Registered: ‎03-06-2006
Message 10 of 10 (204 Views)

Re: command 'let'

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

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation