On Tue 23 Jul 2024 at 15:00:12 (-0400), Greg Wooledge wrote: > 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.
Yes, I think I misinterpreted what you were criticising, sorry. > 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. Yes, he should be able to achieve his ends with no variables at all (using bash), unless he wants to parameterise the /mnt/data/keith/Documents/ part of the path. Something like: #!/bin/bash mkdir -p "/mnt/data/keith/Documents/copying-$(date --iso-8601)-dir" && cd "$_" cp whatever-files-are-to-be-copied ./ If that file is executable and called /path-to/copy-files, then an entry like: */2 * * * * [ -x /path-to/copy-files ] && /path-to/copy-files in his crontab should run it every couple of minutes (to test it). Using --iso-8601, or a format like it, will make the directories sort in the right order. Was using daynumber an attempt to skirt round this issue? If so, the year had better come first. Is this what the OP is after? Cheers, David.