Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] typeset: set $? on incidental error



On 01/15/2016 09:46 AM, Mikael Magnusson wrote:
> On Fri, Jan 15, 2016 at 7:26 AM, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
>> Eric Cook wrote on Thu, Jan 14, 2016 at 00:24:36 -0500:
>>> On 01/13/2016 07:13 PM, Daniel Shahaf wrote:
>>>> The 'typeset' family of builtins doesn't set $? when one would expect it
>>>> to do so:
>>>>
>>>>     % x=$(true) y=$(exit 42); echo $?
>>>>     42
>>>>     % local x=$(true) y=$(exit 42); echo $?
>>>>     0
>>>>
>>>> This patch makes 'typeset' behave as ordiary assignment does.
>>>
>>>
>>> But who expects that?
>>
>> I did.
> 
> local/typeset is a command, and it was successful, so I don't see why
> $? should be set to anything else than 0.
> % true x=$(false); echo $?
> 0
> is technically exactly the same situation as your above second command.
> 

But typeset should exit > 0 when it does fail to assign a parameter.

% ksh -c 'typeset -r foo=foo; typeset -r foo=bar'; echo $?
ksh: foo: is read only
1
% bash -c 'typeset -r foo=foo; typeset -r foo=bar'; echo $?
bash: line 0: typeset: foo: readonly variable
1
% zsh -c 'typeset -r foo=foo; typeset -r foo=bar'; echo $?
zsh:1: read-only variable: foo
0



Messages sorted by: Reverse Date, Date, Thread, Author