On 10/16/2012 03:08 AM, DJ Mills wrote:
Do not use for to iterate over the output of an unquoted command substitution.
Well, I wanted to keep it simple in this case.
Instead, use a while read loop. See http://mywiki.wooledge.org/DontReadLinesWithFor and http://mywiki.wooledge.org/BashFAQ/001
Thanks, that FAQ is really useful.
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