Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] typeset: set $? on incidental error
- X-seq: zsh-workers 37699
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Mikael Magnusson <mikachu@xxxxxxxxx>
- Subject: Re: [PATCH] typeset: set $? on incidental error
- Date: Wed, 20 Jan 2016 07:47:52 +0000
- Cc: zsh workers <zsh-workers@xxxxxxx>
- In-reply-to: <CAHYJk3T6hkQez_zUsRKngRoAm80Xr5Od-=51KWGf9bRWkmRqaA@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20160114001336.GA11173@tarsus.local2> <56973114.90807@gmx.com> <20160115062645.GB12223@tarsus.local2> <CAHYJk3QLCCVmZf4efzQgxs3haKv2mssQk3cGQXd5fm7DK7dgGg@mail.gmail.com> <20160118022557.GE3979@tarsus.local2> <CAHYJk3T6hkQez_zUsRKngRoAm80Xr5Od-=51KWGf9bRWkmRqaA@mail.gmail.com>
Mikael Magnusson wrote on Mon, Jan 18, 2016 at 05:38:17 +0100:
> On Mon, Jan 18, 2016 at 3:25 AM, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> > Mikael Magnusson wrote on Fri, Jan 15, 2016 at 15:46:09 +0100:
> >> 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.
> >
> > I wouldn't call it successful: I asked for the parameter x to be created
> > as a scalar and assigned a value and only part of my request was
> > accomplished.
>
> That's not true, the parameter is created and assigned the value you
> asked for (your command subst had empty output so the parameter is ""
> but if you did local y=$(echo hi; exit 42) it would be "hi".)
In real-life examples, if the command subst had a non-zero exit status,
the value would typically _not_ be the one I asked for:
% cd $(mktemp -d)
% local mtime=$(zstat +mtime myfile)
zstat: myfile: no such file or directory
% echo ${(q)mtime} $?
'' 1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author