zsh-workers
 help / color / mirror / code / Atom feed
From: Eric Cook <llua@gmx.com>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] typeset: set $? on incidental error
Date: Sat, 23 Jan 2016 22:32:48 -0500	[thread overview]
Message-ID: <56A445E0.50706@gmx.com> (raw)
In-Reply-To: <20160123235300.GC20278@tarsus.local2>

On 01/23/2016 06:53 PM, Daniel Shahaf wrote:
> Between all the replies I'm convinced that the builtin interface of
> 'local' shouldn't be changed: «builtin local x=$(false)» should set $?
> to 0.  (I meant to say that in a previous email.)
> 
> However, the question remains, in my eyes, whether the change should be
> made to the reserved word interface.  The reserved word 'typeset' is not
> a command, but part of the shell's language, so in
> .
>     typeset x=$(foo) y=$(bar)
> .
> the last command executed is 'bar'.  I would expect that line to behave
> as similarly to
> .
>     x=$(foo) y=$(bar)
> .
> as possible, so for example, I'd expect the former to set $? to the exit
> code of 'bar', as the latter statement does.
> 
> Cheers,
> 
> Daniel
> 

1(again): the other shells with typeset don't behave that way,
the chances of those shells seeing this a good idea and implementing it
are pretty slim in my opinion.

typeset originated in ksh and ksh93's development has pretty much stalled
over the past few years. When not following posix sh, bash tends to align with
the way ksh does things. needless to say that the other kshs tend to do the same.

Most likely resulting in one more way our typeset differs. zsh's typeset became
a reserved word recently in an attempt behave more like the other typesets.

2: typeset while now part of the `language', still retains it's own exit statuses
from when it was a builtin command.
''
typeset -T foo=bar baz=qux; echo $?; typeset -p foo baz
typeset: second argument of tie must be array: baz
1
typeset: no such variable: foo
typeset: no such variable: baz
''

So in the event that typeset _and_ your arbitrary commands errors, what should $?
be set to?
''
typeset -Z 1.1 foo=$(exit 42)
echo $? # 1 or 42?
''

3: in the `real world' if you are assigning a parameter via command substitution
and there is a possibility that the command substitution could return nothing.
You would get the parameter a default value. During assignment or during expansion.
''
typeset foo=${"$(exit 42)":-default}
# or
echo ${foo:=default} # or :-
''


  reply	other threads:[~2016-01-24  3:38 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-14  0:13 Daniel Shahaf
2016-01-14  4:58 ` Bart Schaefer
2016-01-14  5:24 ` Eric Cook
2016-01-15  6:26   ` Daniel Shahaf
2016-01-15 14:46     ` Mikael Magnusson
2016-01-15 14:54       ` Eric Cook
2016-01-15 15:49         ` Peter Stephenson
     [not found]       ` <20160118022557.GE3979@tarsus.local2>
2016-01-18  4:38         ` Mikael Magnusson
2016-01-18 13:33           ` Mikael Magnusson
2016-01-20  7:47           ` Daniel Shahaf
2016-01-20 15:00             ` Eric Cook
2016-01-23 23:53               ` Daniel Shahaf
2016-01-24  3:32                 ` Eric Cook [this message]
2016-01-26 22:50                   ` Daniel Shahaf
2016-01-27  4:15                     ` Error status of "repeat" (was Re: [PATCH] typeset: set $? on incidental error) Bart Schaefer
2016-01-27  4:38                       ` Bart Schaefer
2016-01-27  9:52                       ` Peter Stephenson
2016-01-29  9:18                         ` Daniel Shahaf
2016-01-29  9:29                           ` Peter Stephenson
2016-01-29 10:25                             ` Daniel Shahaf
2016-01-27  4:17                     ` [PATCH] typeset: set $? on incidental error Bart Schaefer
2016-01-29  9:18                       ` Daniel Shahaf
2016-01-30  7:46                         ` typeset docs flow " Daniel Shahaf
2016-01-30 19:47                           ` Bart Schaefer
2016-01-31  0:49                             ` Jun T.
2016-01-31 17:03                               ` Bart Schaefer
2016-02-01  3:23                                 ` Jun T.
2016-02-01  5:41                                   ` Bart Schaefer
2016-01-21 14:22             ` Vincent Lefevre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56A445E0.50706@gmx.com \
    --to=llua@gmx.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).