Quantcast
Channel: Viktor Balogh's HP-UX blog » System Internals
Viewing all articles
Browse latest Browse all 8

Variable sizes in KSH

$
0
0

It looks like the POSIX shell doesn’t support variable sizes greater than 2 Gigabytes. In the following example, the LIMIT variable is of 1 Gbyte, and the VALUE is 4 GBytes.

# LIMIT=1073741824
# VALUE=4294967296
# if [ $LIMIT -lt $VALUE ]
> then
> echo "exceeds limit"
> else
> echo "passed"
> fi
passed
#

However, the above output should be “exceeds limit”. That’s because the POSIX shell only has 32 bits. In 11.23 ksh uses 64 bits, so either use /usr/bin/ksh or the Korn93 shell from CDE which is reachable under /usr/dt/bin/dtksh. Another solution might be to leverage the power of “bc”. In this case note that you must feed the values as a here-document and not as external shell variables.


Viewing all articles
Browse latest Browse all 8

Trending Articles