bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Command substitution and errexit


From: Nikolai Kondrashov
Subject: Re: Command substitution and errexit
Date: Tue, 16 Oct 2012 10:30:24 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.7) Gecko/20120922 Icedove/10.0.7

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]