bug-bash
[Top][All Lists]
Advanced

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

Re: local keyword hides return code of command substitution


From: Greg Wooledge
Subject: Re: local keyword hides return code of command substitution
Date: Tue, 22 Sep 2015 11:45:20 -0400
User-agent: Mutt/1.4.2.3i

On Tue, Sep 22, 2015 at 10:19:56AM -0400, idallen@home.idallen.ca wrote:
> Description:
>       Adding a "local" keyword to a variable assignment hides the
>       return code of a command substitution.  Same problem in both
>       bash and dash shells.

Yes, this is how it works.  If you care about the return value of a
command used to initialize a local variable, you have to write it in
two steps:

foo() {
    local foo
    foo=$(bar) || return
}

http://mywiki.wooledge.org/BashPitfalls has this and many more.



reply via email to

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