[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Antw: [EXT] Re: declare XXX=$(false);echo $?
From: |
Ulrich Windl |
Subject: |
Antw: [EXT] Re: declare XXX=$(false);echo $? |
Date: |
Mon, 05 Dec 2022 08:47:12 +0100 |
Dale, thanks for explaining.
So basically the behavior is as documented (not a bug), but the design
decision was poor:
declare a
a=b
has a different semantic as
declare a=b
which I consider to be bad.
Ulrich
>>> "Dale R. Worley" <worley@alum.mit.edu> schrieb am 02.12.2022 um 17:39 in
Nachricht <878rjpahfz.fsf@hobgoblin.ariadne.com>:
> Chet Ramey <chet.ramey@case.edu> writes:
>> On 12/2/22 5:28 AM, Ulrich Windl wrote:
>>> Surprisingly "declare XXX=$(false);echo $?" outputs "0" (not "1")
>>> There is no indication in the manual page that "declare" ignores the
>>exit code of commands being executed to set values.
>>
>> Why do you think it should? `declare' has a well-defined return status.
>
> There it is, end of "SIMPLE COMMAND EXPANSION":
>
> If there is a command name left after expansion, execution proceeds
> as
> described below. Otherwise, the command exits. If one of the
> expan‐
> sions contained a command substitution, the exit status of the
> command
> is the exit status of the last command substitution performed.
> If
> there were no command substitutions, the command exits with a status
> of
> zero.
>
> and:
>
> declare [-aAfFgiIlnrtux] [-p] [name[=value] ...]
> typeset [-aAfFgiIlnrtux] [-p] [name[=value] ...]
> [...]
> The return value
> is 0 unless an invalid option is encountered, an attempt is
> made
> to define a function using ``-f foo=bar'', an attempt is made
> to
> assign a value to a readonly variable, an attempt is made to
> as‐
> sign a value to an array variable without using the compound
> as‐
> signment syntax (see Arrays above), one of the names is not
> a
> valid shell variable name, an attempt is made to turn off
> read‐
> only status for a readonly variable, an attempt is made to
> turn
> off array status for an array variable, or an attempt is made
> to
> display a non-existent function with -f.
>
> If you input "XXX=$(false)", there isn't a command name, it's a sequence
> of assignments, and "the exit status of the command is the exit status
> of the last command substitution performed". But if you input "declare
> XXX=$(false)", you're executing the "declare" command, and the exit
> status doesn't depend on the command substitution.
>
> Dale
Re: declare XXX=$(false);echo $?, Martin D Kealey, 2022/12/02