From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: print builtin preceded by parameter assignment
Date: Thu, 11 Apr 2019 14:42:08 -0700 [thread overview]
Message-ID: <CAH+w=7ZwbhcxGUM1eeu8jY3d12toFTgbCfvYPEdHhUkdtdWcuA@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7a7WfCX7nRRN7rOk8ZMpOSRV5Tt0a9CHtYJhikhffrmLg@mail.gmail.com>
On Thu, Apr 11, 2019 at 1:58 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> The actual takeaway here is that TZ has to be pushed into the actual
> environ strings, not just set temporarily as a local to the shell, in
> order for the system time libraries to apply it to strftime et al.
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
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(). Explicitly resetting TZ fixes it:
% export TZ=PST8PDT
% date
Thu Apr 11 14:29:25 PDT 2019
Also, once TZ is both marked for export and has a valid value,
everything works the way Vincent expects:
% TZ=UTC print -P "%D{%c %Z}"
Thu Apr 11 21:29:36 2019 UTC
% date
Thu Apr 11 14:29:43 PDT 2019
%
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.
As an aside, TZ is explicitly referenced and manipulated when using
zsh/datetime strftime builtin, so it might not suffer from any of
these problems. I haven't tested it
next prev parent reply other threads:[~2019-04-11 21:43 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 [this message]
2019-04-24 12:31 ` Vincent Lefevre
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='CAH+w=7ZwbhcxGUM1eeu8jY3d12toFTgbCfvYPEdHhUkdtdWcuA@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--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).