Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #11544
| From | Eric Blake <eblake@redhat.com> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Re: local keyword hides return code of command substitution |
| Date | 2015-09-22 09:44 -0600 |
| Organization | Red Hat, Inc. |
| Message-ID | <mailman.1603.1442936679.19560.bug-bash@gnu.org> (permalink) |
| References | <20150922141956.9E7ED81A59@idallen-oak.home.idallen.ca> |
[Multipart message — attachments visible in raw view] - view raw
On 09/22/2015 08:19 AM, idallen@idallen-fibe.dyndns.org 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. > Not a bug. $() substition can only affect $? if it is executed in isolation, and not as an argument to some other command. 'local' is some other command. And while 'local' is not (yet) in POSIX, the behavior is the same for 'export', which IS specified by POSIX. For more details, read: http://austingroupbugs.net/view.php?id=960#c2777 in particular the section that says: > Note that, unless X was previously marked readonly, the value of $? after > > export X=$(false) > > will be 0 (because export successfully set X to the empty string) and that execution continues, even if set -e is in effect. In order to detect command substitution failures, a user must separate the assignment from the export, as in > > X=$(false) > export X So, as you discovered, > The work-around is to use "local" to declare the variable first, > then do the command substitution assignment on another line and > check the return code there. That is not a workaround, so much as the correct behavior. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Back to gnu.bash.bug | Previous | Next | Find similar
Re: local keyword hides return code of command substitution Eric Blake <eblake@redhat.com> - 2015-09-22 09:44 -0600
csiph-web