Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #11546
| Path | csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!enother.net!enother.net!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!171.64.64.130.MISMATCH!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Stephane Chazelas <stephane.chazelas@gmail.com> |
| Newsgroups | gnu.bash.bug |
| Subject | Re: local keyword hides return code of command substitution |
| Date | Tue, 22 Sep 2015 17:22:15 +0100 |
| Lines | 30 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.1608.1442938946.19560.bug-bash@gnu.org> (permalink) |
| References | <20150922141956.9E7ED81A59@idallen-oak.home.idallen.ca> <20150922154520.GM25574@eeg.ccf.org> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| X-Trace | usenet.stanford.edu 1442938947 9135 208.118.235.17 (22 Sep 2015 16:22:27 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| Cc | bash@packages.debian.org, bug-bash@gnu.org, idallen@home.idallen.ca |
| To | Greg Wooledge <wooledg@eeg.ccf.org> |
| Envelope-to | bug-bash@gnu.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=dd2d4+FJuCJflNNGy909Rn9iwMXmIreQGop4PBKk22g=; b=xIOV11YqvJ0EF85tLKrE8mwgZNAmPVPvC14zHughFwFcraCZVQqShCFsyrx52kxt1i +Zcd0/PgHxDbgQF9bkD1Xthuxvpw6J8ibgSVRU0K0Kuo2Da+PTq1dH8H9BLtj8ynDfNr gc1LPzALp6ZSq4JLzg0sVov7PdbZrEE/aUfqtzRRU2qUUj5HQRq9GUUIxCaUHfN6o5lP H5wUDb/I/zDPSgG543G+funkwG5lw0+cC3PVpj5/TVRjeo2Vmatk2ODnYYanQl8H9xFk b4OHDUuRYSLDIrEC7TGR4wSMZu1IWH8thO7lc+2ixDZPigccpPj4fVy70UhNTBtIc3Uc qpKQ== |
| X-Received | by 10.180.24.3 with SMTP id q3mr21887073wif.24.1442938939927; Tue, 22 Sep 2015 09:22:19 -0700 (PDT) |
| Content-Disposition | inline |
| In-Reply-To | <20150922154520.GM25574@eeg.ccf.org> |
| User-Agent | Mutt/1.5.21 (2010-09-15) |
| X-detected-operating-system | by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). |
| X-Received-From | 2a00:1450:400c:c05::22e |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.14 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <http://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| X-Received-Bytes | 3347 |
| X-Received-Body-CRC | 1165045127 |
| Xref | csiph.com gnu.bash.bug:11546 |
Show key headers only | View raw
2015-09-22 11:45:20 -0400, Greg Wooledge:
> 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
> }
[...]
It also avoids problems with some other shells that support
"local" as a normal command when one forgets to quote the
$(command-subtitution) (where for instance
local foo=$(echo bar baz) is like local foo=bar baz)
Note that for "readonly", the assignment needs to be done first:
foo=$(bar) || return
readonly foo
--
Stephane
Back to gnu.bash.bug | Previous | Next | Find similar
Re: local keyword hides return code of command substitution Stephane Chazelas <stephane.chazelas@gmail.com> - 2015-09-22 17:22 +0100
csiph-web