In bash, if you do this:
mkdir /tmp/empty array=(/tmp/empty/*)
you find that array now has one element, \"/tmp/empty/*\"
array
\"/tmp/empty/*\"
Unset it when done:
shopt -u nullglob
And properly (i.e. storing the previous state):
shopt -u | grep -q nullglob && changed=true && shopt -s nullglob ... do whatever you want ... [ $changed ] && shopt -u nullglob; unset changed