Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: let unset array element remove compatible with bash
On Feb 22, 3:28am, Daniel Lin wrote:
}
} Can any developer consider to enhance zsh's function like "unset var[2]"?
}
} $unset var[2] ###### BASH only delete one element
} $var[2]=() ###### ZSH only delete one element
I've started a thread on zsh-workers about this, but:
var[3]=() does not mean the same thing that unset var[3] would imply.
In zsh, if you assign to a position that is "off the end" of the array,
zsh manufactures empty array elements to "fill in the gap". Try this
in each of bash and zsh:
unset gappy
gappy[9]=nine
for g in "${gappy[@]}"; do echo /$g/; done
Now in zsh:
unset gappy
gappy=(one)
gappy[3]=()
for g in "${gappy[@]}"; do echo /$g/; done
Note that assigning an empty array to the one-element slice gappy[3]
has caused gappy[2] to exist as an empty element.
Bash is using some kind of sparse structure to store its arrays.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author