I also don't understand the point of using a regex like that, seems to
be way more complicated than it needs to be. A simple glob will
suffice here.
Assuming you're writing bash and not POSIX sh:
while read -r attr state; do
if [[ $shellopts = *:"$attr":* ]]; then
set -o "$attr"
else
set +o "$attr"
fi
done< <(set -o)
As you point out later, it won't work, but thanks, that's a nice trick with
"read" and process substitution - didn't think of it.
Sincerely,
Nick