mkcd ()
{
mkdir -p $1
cd $1
}
in the form :~ $> mkcd /mnt/data/keith/Documents/$YEAR/$MTH$YEAR/$DOYR.$YEAR/
I am transferred to
/mnt/data/keith/Documents/2024/Jul2024/196.2024 $> ie $DOYR is using
the wrong day number
Why is the env var $DOYR not updating when I use it at the command prompt
AND for that matter in a script - clearly the system is or I'd be getting
the wrong day # at my command prompt?
Why am I not getting a warning that the dir already exists?
I want to run the script as a cron job, to keep a daily copy of a few files
- mainly to prove that I can do it.
From the tab I had used earlier, ran source .bashrc
then
:/tmp/205.2024 $> mkcd /tmp/day$DOYR.$YEAR
So, now question is how can I get cron to 'source .bashrc' I'm thinking add that line to my script?
The day# in my command prompt increments when I start in the morning. Maybe I need to press enter.
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,
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.
Really, the fundamental problem here is that you should not be storing date/time information in long-lived variables, and then trying to use
those variables at an indeterminate point in the future.
Anything that needs to act upon the current date should fetch the current date immediately before acting.
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.
So when I opened my xterm this morning, I saw:
keith@lenv0
Tue 23Jul2024@19:19:30 205.2024 AEST
:~ $>
You have new mail in /var/spool/mail/keith
Pressed enter, and the day# updated:
keith@lenv0
Wed 24Jul2024@09:48:36 206.2024 AEST
:~ $>
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 01:32:11 |
Calls: | 10,385 |
Calls today: | 2 |
Files: | 14,057 |
Messages: | 6,416,578 |