I don't have enough reputation to add a real answer, but when using the
shopt -s dotglob && rm /path/to/directory/*
solution in bash, (shopt -s dotglob && rm /path/to/directory/*)
(with parentheses) will prevent shopt -s dotglob
from leaking beyond this one command. (Parentheses run the contained commands in a subshell.)