From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 73905dc5 for ; Wed, 10 Apr 2019 14:12:07 +0000 (UTC) Received: (qmail 859 invoked by alias); 10 Apr 2019 14:11:51 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23923 Received: (qmail 29577 invoked by uid 1010); 10 Apr 2019 14:11:51 -0000 X-Qmail-Scanner-Diagnostics: from cventin.lip.ens-lyon.fr by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.1/25412. spamassassin: 3.4.2. Clear:RC:0(140.77.13.17):SA:0(-1.9/5.0):. Processed in 2.188759 secs); 10 Apr 2019 14:11:51 -0000 X-Envelope-From: vincent@vinc17.net X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at vinc17.net does not designate permitted sender hosts) Date: Wed, 10 Apr 2019 16:11:13 +0200 From: Vincent Lefevre To: zsh-users@zsh.org Subject: Re: print builtin preceded by parameter assignment Message-ID: <20190410141113.GD15169@cventin.lip.ens-lyon.fr> Mail-Followup-To: zsh-users@zsh.org References: <20190410125557.GA19114@cventin.lip.ens-lyon.fr> <1554902053.6252.6.camel@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1554902053.6252.6.camel@samsung.com> X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/1.11.4+145 (46b4c0aa) vl-114617 (2019-04-08) On 2019-04-10 14:14:13 +0100, Peter Stephenson wrote: > On Wed, 2019-04-10 at 14:55 +0200, Vincent Lefevre wrote: > > It seems that the print builtin doesn't take into account a change > > of the environment with a parameter assignment. For instance: > >  > > cventin% zsh -c 'TZ=UTC print -P "%D{%c}"' > > 2019-04-10T14:53:50 CEST > > cventin% zsh -c 'export TZ=UTC; print -P "%D{%c}"' > > 2019-04-10T12:53:53 UTC > >  > > Is there any (undocumented?) reason or is this a bug? > > It's certainly the case that such assignments only go into the > environment, and aren't processed within the shell. > > I *think* this is standard behaviour: > > http://pubs.opengroup.org/onlinepubs/9699919799/ > > 2.9.1 specifies that unless the command is a special builtin utility, > the "current execution environment" is not affected by the assignment; > the value is simply exported.  I'd certainly assume the time zone seen > by % escapes is part of the current execution environment.  Neither > print (obvioussy) nor echo are special builtin utilities. > > As this is a standard, I may simply have misread it. This is not how I interpret it (see below). But anyway, non-special builtins are not in the scope of POSIX, unless you regard these builtins as functions (in the sense, with a similar behavior), in which case, the current behavior seems to be a bug. POSIX distinguish 4 cases with a command name, and it depends on which case you assume to apply to the "print" builtin. 1. If the command name is not a special built-in utility or function, the variable assignments shall be exported for the execution environment of the command [...] In this case, the variable assignments should affect the output. 2. If the command name is a standard utility implemented as a function, the effect of variable assignments shall be as if the utility was not implemented as a function. The "print" builtin is not a standard utility, so that this does not apply (otherwise this is similar enough to cases 1 and 4). 3. If the command name is a special built-in utility, variable assignments shall affect the current execution environment. If you want to regard the "print" builtin as a special built-in utility, the variable assignments should affect its output. 4. If the command name is a function that is not a standard utility implemented as a function, variable assignments shall affect the current execution environment during the execution of the function. Again, in this case, if you regard the "print" builtin as similar to some (opaque) function, the variable assignments should affect its output. As a summary, it is expected that in *any* case, variable assignments affect the output. When POSIX talks about the current execution environment is what occurs around the execution of the command/function/... (e.g. expansions and code run after the execution of the command). -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)