I can create an array, then delete from this array
$ foo=(a b c)
$ unset foo[0]
$ echo ${foo[*]}
b c
However if nullglob
is set then I cannot delete from the array
$ shopt -s nullglob
$ foo=(a b c)
$ unset foo[0]
$ echo ${foo[*]}
a b c
unset 'foo[0]'
Bash thinks the
var[1]
is a glob, doesn't find a file that matches it, and per instruction ofnullglob
removes it, causing your script to rununset
instead ofunset var[1]
- and nothing gets unset. The correct way to fix this issue is to quote the variable name (and always specify-v
explicitly):unset -v 'var[1]'
.