Re: making a variable local counts as a statement as per $?
David <[email protected]>
| Newsgroups | gmane.comp.shells.bash.bugs |
|---|---|
| Message-ID | <CAMPXz=oOy2xRFSEB=xqzW_5fpb3S_=BSHB+P4JYR6kUTQRWTxQ@mail.gmail.com> |
On Tue, 24 Feb 2026 at 10:20, Luca Saiu <[email protected]> wrote: > f () { a=$(false); echo $?; }; f # This prints 1 as expected > > f () { local a=$(false); echo $?; }; f # This prints 0 > > The way I interpret this is that making the variable local “counts as a > statement”, and overwrites the value of $? with 0, since making the > variable local succeeds. Is this correct? Is this the intended > semantics? I certainly find it counterintuitive, and cannot see it > being documented. Hi, regarding documentation, the exit status of 'local' command is explained both by 'help local', and by 'man bash' section "SHELL BUILTIN COMMANDS". Also, this list is for discussing bugs, so if not doing that then it's more appropriate to use the 'help-bash' list at https://lists.gnu.org/mailman/listinfo/help-bash