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