zsh-users
 help / color / mirror / code / Atom feed
From: Vincent Lefevre <vincent@vinc17.net>
To: zsh-users@zsh.org
Subject: Re: print builtin preceded by parameter assignment
Date: Wed, 24 Apr 2019 14:31:44 +0200	[thread overview]
Message-ID: <20190424123144.GA21402@zira.vinc17.org> (raw)
In-Reply-To: <CAH+w=7ZwbhcxGUM1eeu8jY3d12toFTgbCfvYPEdHhUkdtdWcuA@mail.gmail.com>

On 2019-04-11 14:42:08 -0700, Bart Schaefer wrote:
> The trick is to mark TZ exported before you try to use it as a prefix
> assignment.
> 
> % echo $+TZ
> 0
> % export TZ
> % echo $+TZ
> 1
> % print -P "%D{%c %Z}"
> Thu Apr 11 14:27:39 2019 PDT
> % TZ=UTC print -P "%D{%c %Z}"
> Thu Apr 11 21:27:58 2019 UTC

This is even more confusing: the "export" status should not have
an effect in a variable assignment before a command (in particular,
a builtin).

Actually there is another inconsistency without the "export":

zira% echo $+TZ $+LC_ALL
0 0
zira% print -P "%D{%c %Z}"
Wed Apr 24 14:19:39 2019 CEST
zira% TZ=UTC0 LC_ALL=fr_FR.utf8 print -P "%D{%c %Z}"
mer. 24 avril 2019 14:19:50 CEST CEST

Following the (IMHO, invalid) justification for TZ not being taken
into account with a builtin, the LC_ALL assignment should have also
been ignored. But this is not the case.

Ditto for CDPATH:

zira% printenv CDPATH
zira% cd home
cd: no such file or directory: home
zira% CDPATH=/ cd home
/home

> Here's a semi-related oddity -- once the timezone is changed, it does
> not change back, even though the TZ variable is not set:
> 
> % echo $TZ
> 
> % date
> Thu Apr 11 21:28:18 UTC 2019
> 
> Oops, the timezone remains UTC even though the variable is no longer
> set.  This has to be a side-effect of calling localtime() in
> promptexpand().

This is even worse.

[...]
> So the "bug" if there is one is that variables that aren't marked for
> export don't magically become exported when used before a builtin in a
> prefix assignment.

There are several bugs (perhaps all related):

1. The fact that TZ remains exported with a value different
   from $TZ.

2. The fact that TZ and other variables (at least LC_ALL and CDPATH)
   are handled differently with a variable assignment before a
   builtin, when not exported.

3. The fact that for TZ, the "export" status has an effect on
   the value taken into account in a builtin.

IMHO, for (2), the best solution would be to fix (2) to follow
the behavior of LC_ALL/CDPATH/... (which would correspond to my
original request). And this would make (3) pointless.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

  reply	other threads:[~2019-04-24 12:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20190410125753epcas1p4052249a86c562165e1fe2a485d70e70b@epcas1p4.samsung.com>
2019-04-10 12:55 ` Vincent Lefevre
2019-04-10 13:14   ` Peter Stephenson
2019-04-10 14:11     ` Vincent Lefevre
2019-04-10 14:39       ` Peter Stephenson
2019-04-10 17:25         ` Bart Schaefer
2019-04-11 10:40           ` Vincent Lefevre
2019-04-11 20:58             ` Bart Schaefer
2019-04-11 21:42               ` Bart Schaefer
2019-04-24 12:31                 ` Vincent Lefevre [this message]
2019-04-24 16:00                   ` Bart Schaefer
2019-04-25 19:47                     ` Bart Schaefer
2019-04-11 10:45         ` 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=20190424123144.GA21402@zira.vinc17.org \
    --to=vincent@vinc17.net \
    --cc=zsh-users@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).