On Tue, Jul 23, 2024 at 17:02:08 +1000, Keith Bainbridge wrote:
> mkcd ()
> {
>     mkdir -p $1
>     cd $1
> }

You're missing quotes.  Two sets.  You probably also want && between
the two commands, to check for the success of the mkdir before attempting
a cd.

>  in the form  :~   $>   mkcd
> /mnt/data/keith/Documents/$YEAR/$MTH$YEAR/$DOYR.$YEAR/

Where do these variables (YEAR, MTH, DOYR) come from?

> I am transferred to
> /mnt/data/keith/Documents/2024/Jul2024/196.2024   $>    ie $DOYR is using
> the wrong day number

How/where did you set it?

> 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?

We don't know, because you haven't shown us where you're setting it.

> Why am I not getting a warning that the dir already exists?

Because you used mkdir -p.  Please read what -p does.

> 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.

A cron job will not inherit those variables from your shell session,
or wherever it is you're defining them.  You'll have to set them within
the cron job, or use the date(1) command, or use bash's printf %()T
formatter to generate date/time strings.

Reply via email to