[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
printf builtin retains timezone from un-set TZ environment variable
From: |
Travis Everett |
Subject: |
printf builtin retains timezone from un-set TZ environment variable |
Date: |
Sat, 13 Jul 2019 12:31:31 -0500 |
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: darwin17.7.0
Compiler: clang
Compilation CFLAGS: -g -O2 -Wno-parentheses -Wno-format-security
uname output: Darwin f638f97d 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr
25 23:16:27 PD$
Machine Type: x86_64-apple-darwin17.7.0
Bash Version: 5.0
Patch Level: 7
Release Status: release
*Description:*
I've noticed that a timezone explicitly set in the TZ environment variable
can get cached (if any date-using command/builtin is run) and then show up
(at least) in dates produced by the printf builtin's "%(...)T" formats even
after the TZ variable is unset.
I played around with this for a bit and identified two ways to get the
timezone to re-set:
- Run an external command. I have yet to find an external command that
didn't correct it, so I suspect this behavior is intrinsic to the API calls
made when running an external command. It's also possible I'm too
unimaginative to find an external command that *doesn't* invoke date APIs
:).
- Set the TZ variable inline and run any builtin (i.e.,
`TZ=:/etc/localtime :`).
*Repeat-By:*
---- tzcache.sh ----
echo $BASH_VERSION
export TZ=Antarctica/South_Pole
printf "TZ: $TZ\n\t%(%+)T\n"
unset TZ
# still prints the now-unset timezone
printf "TZ: $TZ\n\t%(%+)T\n"
# to reset it
# run any external command
# or any builtin with an inline TZ setting
TZ=:/etc/localtime :
printf "TZ: $TZ\n\t%(%+)T\n"
--------------------
$ env -i $(which bash) --norc --noprofile tzcache.sh
5.0.7(1)-release
TZ: Antarctica/South_Pole
Sun Jul 14 05:21:49 NZST 2019
TZ:
Sun Jul 14 05:21:49 NZST 2019
TZ:
Sat Jul 13 12:21:49 CDT 2019
Cheers,
Travis
- printf builtin retains timezone from un-set TZ environment variable,
Travis Everett <=