I being boggled down since last 26 hrs with a weird issue in ksh with associate array and unset
I have a function
Code:
function setMyParms
{
nameref refOptions=$1 # This is an associate array from parent script
typeset -a cmd
...
for key in "${!refOptions[@]}"; do
cmd=('text')
cmd+=('text')
cmd+=('text')
...
execCMD cmd
done
}
function execCmd
{
nameref refCmd=$1
typeset cmd
print "Before unsetting refCmd[0], array length is ${#refCmd[@]}"
for arg in "${refCmd[@]}"
do
print "${arg}"
done
unset 'refCmd[0]'
print "After unsetting refCmd[0], array length is ${#refCmd[@]}"
for arg in "${refCmd[@]}"
do
print "${arg}"
done
}
This code is behaving very weird.
The first invocation of execCmd from setParms 'for' loop, the 'unset refCmd[0]' is removing the entire array.
Code:
execCMD:> print 'Before unsetting refCmd[0], array length is 3'
execCMD:> print 2Fusr%2Fbin%2Fnet%20conf%20delparm
execCMD:> print global
execCMD:> print client%20use%20spnego
execCMD:> unset 'refCmd[0]'
execCMD:> print 'After unsetting refCmd[0], array length is 0'
It runs fine for the rest of the for loop though.
I am not able to debug why the unset removes all the elements, any only for first invocation