From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 400 invoked by alias); 24 Jan 2016 03:38:03 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37754 Received: (qmail 24735 invoked from network); 24 Jan 2016 03:38:01 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.0 Subject: Re: [PATCH] typeset: set $? on incidental error To: zsh-workers@zsh.org References: <20160123235300.GC20278@tarsus.local2> From: Eric Cook X-Enigmail-Draft-Status: N1110 Message-ID: <56A445E0.50706@gmx.com> Date: Sat, 23 Jan 2016 22:32:48 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <20160123235300.GC20278@tarsus.local2> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:bhZOIZrUt5DXDG4sFfqjmkRv1yM1eAcw2Gq/x1WE0Yf91Z+zlLy SgxC2UY5gTjdQ7WZoKjoHPjnJrGZQG1twUKnulN7TtWqG4CG+3BvcV+Qhc7kysKW9kc5+x7 9CTjrzSbfiZ/i8EkM9sKRhMbXl0zuQQd3ujVrD5jGF9HCMzkhRsRKs0xPTXcBzNvnASdBhV pNCnZBtXj3kEVPs1jCpIQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:ENsZ7dv8PIo=:NRt3IM3rMu/5gpH0LRJ6Xs kzN5Jkx0/ikGc3iAiic4gj9osu17/NDwYz2iT9ysial+pfnH/N6f8SaHnsayfGj+fP/IhxybP 02UjNh9F/l6jKG00RTjM00Jn+6pG6mDL7S4BmSzgla9dKNKAARQ2g/EJpG6CWTT9rKFfnIr+A 6FTbkaJpzq0r+vK2dNZ7SVXUacemVVQ9TjtWWEI9JddGYzOanBtaT/kyR9oiV+JiT7zyTluZN rSa6I/YgflOq2uhEaeA3yjIg67KKJWGiT2VVyqWZSl6WpihFC3Uz9PSJZU0PPSX0dwxTwlAKS oLEwqV5+xcEfVNKciM3XZUNEvIXLF6u0VlBVAE+fqnCDnZ9wicq4QvUknNE0MynyR4A9J3smD u89/0IigXF5eDn045mbfF5UEqa3iO4FUYU6nqNWNHZQ+6gG1EQntn6BTXlUOMR+YcdnDMlNhU 5Jhdyls90dRbfMWKI3nEY9wopj6yuQXMISnY0UNL1dPifd8W9l2AkLhIhyCcgBNDDirXClupf NSADd13elU+4HawJWgfSNs1l0k8VXpWyngDDhNn3/+gq3M3XksaO23uPnFENHrv01QjjsW+o9 /RMs+psOdqv+Mv9ATPoR0snvWE4dehj805FoQb/u+B+U3j1ng6TXhoynf6T7OUtyBGqYjoSI+ Oz5PyVqn7L5rlj6OMISJtSfx1N3oDeFMlib44Daayi9r02JUsdpCC9S3KbtBgU/u3nd7AqA+H EJr6h53jaeVi9dR5D1gqBYBQMuD3uSgQ9QjfkXOxiJqbNxEY6Yc7wMkWQE+Og7SmbJKoxrAQW 21xV/42 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 :- ''