bug-bash
[Top][All Lists]
Advanced

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

Re: making a variable local counts as a statement as per $?


From: David
Subject: Re: making a variable local counts as a statement as per $?
Date: Tue, 24 Feb 2026 13:09:55 +0000

On Tue, 24 Feb 2026 at 10:20, Luca Saiu <positron@gnu.org> 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



reply via email to

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