Re: How to update environment variable output
On Tue, Jul 23, 2024 at 13:38:48 -0500, David Wright wrote:
> On Tue 23 Jul 2024 at 09:31:36 (-0400), Greg Wooledge wrote:
> > On Tue, Jul 23, 2024 at 23:22:52 +1000, Keith Bainbridge wrote:
> > > The day# in my command prompt increments when I start in the morning. Maybe I need to press enter.
> >
> > That makes it sound like you're setting the YEAR et al. variables in the
> > PROMPT_COMMAND variable.
> >
> > If that's the case, it's *less* wrong, but only a little bit. You still
> > have the issue that the date might change while you're sitting at a
> > stale shell prompt from yesterday, with stale date/time variables.
>
> Actually, that is what I do want (the time—the date not so much).
> That tells you when the last command finished. Press Return before
> you start a command and you get some idea of how long it takes
> to run. For the current time, press Return.
>
> I think putting the time±date in one's prompt is pretty popular,
Sure. That's a completely different problem from what Keith is describing,
though.
Putting date/time expansions into your PS1 (prompt) causes the system
time to be retrieved when the prompt is displayed. The date/time strings
are rendered and displayed, and then not remembered by the shell.
What Keith is doing is storing components of the date/time in variables
at shell startup, and then using them at some unspecified point in
the future to create a directory. This causes issues when the shell
survives through a day transition (midnight).
Keith's workflow might work well if he rigorously logs out (or at least
closes all shells) every night before midnight, and logs in (or re-opens
his shells) in the morning. But even then, it's still a questionable
implementation. Anything that relies on a human being to remember to
do something is eventually going to fail.
A safer implementation would retrieve the current date at the moment
when it's needed. Your PS1 string does this.
Reply to: