Header Shadow Image


ksh and ksh93: line arithmetic syntax error

While using associative arrays, I run into this little issue using this sample KSH93 code:

#!/bin/ksh93u+

function scmp {
        typeset -A IPAA;

        # Load First File.
        for KEY in $(cat 1.rip); do
                IPA1[KEY]=1;
        done

        # Load Second File.
        for KEY in $(cat 2.rip); do
                IPA2[KEY]=1;
        done
};

function main {
        scmp;
};
main;

Which resulted in this error:

[root@mbpc bin]# ./a.ksh
./a.ksh[23]: main[21]: scmp: line 10: 192.81.0.250: arithmetic syntax error
[root@mbpc bin]#

The real change to address was here and it was to set the IPA1 and IPA2 to associative array type (Had typeset -A IPAA erronously):

#!/bin/ksh93u+

function scmp {
        typeset -A IPA1;           
        typeset -A IPA2;           

        # Load First File.
        (( CNT = 0 ));
        for KEY in $(cat 1.rip); do
                (( CNT++ ));
                IPA1[“${KEY}”]=1;
                print "CNT=|$CNT|";
        done

        # Load Second File.
        for KEY in $(cat 2.rip); do
                IPA2[“”KEY]=1;
        done
};

function main {
        scmp;
};
main;

which naturally fixed the problem.  Of course, the above could be generated for any number of reasons however in this case, it was the typeset lines above:

Cheers,
TK

Subscribe
Notify of
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

     
  Copyright © 2003 - 2025 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License

 

0
Would love your thoughts, please comment.x
()
x
The IT Development and Technology Mini Vault | MicroDevSys.com
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.