[Wylug-discuss] Copy files by date

Paul Brook paul at codesourcery.com
Thu Feb 2 00:34:37 UTC 2012


> > > However ... I still think that for what you're doing you'd be much
> > > better off using rsync than trying to devise your own copying
> > > routine.
> > 
> > for a temporary solution the IT people will not allow any installation
> > of other software.
> 
> Ah, I was considering rsync to be so standard that it would be installed
> already on all Unix-like systems.

If you can't get basics like rsync then I would run away screaming if at all 
possible.  At that point you bascally have to reinvent the wheel using only 
square pegs.

> > >   if [[ "$FILE" == *AA*.txt ]]
> > > 
> > > Though note that that pattern will match things like these, which
> > > 
> > > you might've meant to categorize under ZZ rather than AA:
> > >   ZZ_AARDVARK.txt
> > >   AAAARGH/ZZ.txt
> > 
> > Noted, each file has a unique reference number, AA, BA etc is the first 2
> > letters before the reference number linking it to a section.
> 
> So a pattern of "${FILE##*/}" == AA*.txt would be safer, ensuring that
> the AA doesn't match in the directory name or somewhere other than at
> the start of the filename.

Or use basename(1).

FWIW the standard idiom for doing glob matching in shell scripts is a case 
statement.  As with most shell functionality it's worth taking the time to 
understandhing how quoting and variable expansion interact[1], and case 
expressions in particular are a bit special.  Once you get your head round 
that it can be a very effective construct.

Paul

[1] The bash manual has a fairly comprehensive chapter on this.  Most people 
just guess, and most get it wrong.



More information about the Wylug-discuss mailing list