Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: print builtin preceded by parameter assignment
- X-seq: zsh-users 23931
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: print builtin preceded by parameter assignment
- Date: Thu, 11 Apr 2019 14:42:08 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=qmfmHaXlDWR6jCO66PZDbwElqYxqLK0IOG9BZPuxXw4=; b=g39+W7Y7qujxJeJ9APFCJOF/X/CtHRXfNjaoGySlkY0J5vlGjj/MfajfMwAOAAddmf lgQntTyJEmyJcRiKH+MKZO4qWa0E8cbuWIfE9E27futc+s05IWgQjfWTuTGsC///RQ67 5G9M6auV4YP5VDQJMHhn324yLNG1h8SzcuYfViQQKQquCLPmOrKdGdcm4MLHElGBUK+g zkkZTXuSdRTiKA8vxPt8HYEEfpl/DEWucRULwEUl8CVbZ8Qn7HcdM0M7fUqa2hYj0UF1 mx+raOqyXQltrg23aVzBpNwRofJM74ZtScvVp69Q31iV3FH6S1LQhEufyiTNOOZTJbnG myjg==
- In-reply-to: <CAH+w=7a7WfCX7nRRN7rOk8ZMpOSRV5Tt0a9CHtYJhikhffrmLg@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CGME20190410125753epcas1p4052249a86c562165e1fe2a485d70e70b@epcas1p4.samsung.com> <20190410125557.GA19114@cventin.lip.ens-lyon.fr> <1554902053.6252.6.camel@samsung.com> <20190410141113.GD15169@cventin.lip.ens-lyon.fr> <1554907186.6252.12.camel@samsung.com> <CAH+w=7bc6oTLWfa5RiNtwdX5ZjT+wi6A3Vb3mxmRc9b8fQH-1A@mail.gmail.com> <20190411104040.GA29775@cventin.lip.ens-lyon.fr> <CAH+w=7a7WfCX7nRRN7rOk8ZMpOSRV5Tt0a9CHtYJhikhffrmLg@mail.gmail.com>
On Thu, Apr 11, 2019 at 1:58 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author