[Top][All Lists]

[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 00:18:37 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.7) Gecko/20120922 Icedove/10.0.7

On 10/16/2012 12:08 AM, Greg Wooledge wrote:
Sidestepping the direct question for a moment, you could use a temporary
file instead of a command substitution to store the output.  Then there
would be no subshell involved.

Thanks, Greg. I don't like creating temporary files unnecessarily, so I went
the route of using SHELLOPTS value instead and massaging it into a set of
"set" calls on restore. Like this:

    declare -r shellopts="$1"
    declare -r on_pattern="^(${shellopts//:/|})\$"
    declare attr

    for attr in `set -o | awk '{print \$1}'`; do
        if [[ $attr =~ $on_pattern ]]; then
            set -o $attr
            set +o $attr

Might need to do something with that awk invocation, though.


reply via email to

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