cancel
Showing results for 
Search instead for 
Did you mean: 

ksh - variable size limitation

Satish Y
Trusted Contributor

ksh - variable size limitation

Hello experts,

It looks like ksh doesn't support variable sizes equal or greater than 2GB (2147483648)

for e.g.,

# SIZE=1073741824

# VALUE=17179869184

# if [ $SIZE -lt $VALUE ]
> then
> echo "not ok"
> else
> echo "ok"
> fi
ok

Where as output should be "not ok"

This is happening because input to the variable VALUE is greater than 2 GB.

# VALUE=17179869184; echo $VALUE
0

Is there any way to overcome this limitation and define variable to accept values greather than 2GB ?

I tried typeset -E & -F, but not working

I know "bc" don't have such limitation, but I can't pass values directly to "bc", because these variables assigned values after some calculations and expressions, unlike I mentioned above where I assigned values directly to simplify

Thanks,
Satish.
Difference between good and the best is only a little effort
2 REPLIES
Dennis Handly
Acclaimed Contributor

Re: ksh - variable size limitation

>It looks like ksh doesn't support variable sizes equal or greater than 2GB (2147483648)

Right. On 11.23, ksh handles 64 bit arithmetic. But the Posix shell only has 32 bit.

>I tried typeset -E & -F, but not working

/usr/dt/bin/dtksh supports them.

>but I can't pass values directly to "bc"

Why not? You can pass them in a here document.
Satish Y
Trusted Contributor

Re: ksh - variable size limitation

CDE not installed on our server, so dtksh doesn't exist
Difference between good and the best is only a little effort