bug-bash
[Top][All Lists]
Advanced

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

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


From: Luca Saiu
Subject: making a variable local counts as a statement as per $?
Date: Tue, 24 Feb 2026 10:20:36 +0000
User-agent: pEp-mail-tool v0.9.100-RC3+ with Gnus v5.13, GNU Emacs 31.0.50, GNU/Linux x86_64-pc-linux-gnu

Hello.

I was surprised to discover that the following two lines behave
differently:


  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.

Thanks, and thanks for your precious work on Bash.

--  
Luca Saiu      https://ageinghacker.net
  GNU Jitter     https://www.gnu.org/software/jitter
  GNU epsilon    https://www.gnu.org/software/epsilon
  pEp-mail-tool  https://codeberg.org/pEp/pEp-mail-tool

I support everyone's freedom of mocking any opinion or belief, no
matter how deeply held, with open disrespect and the same unrelented
enthusiasm of a toddler who has just learned the word "poo".

Attachment: sender_key.asc
Description: application/pgp-keys


reply via email to

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