Subject: Re: Shell hack -- getting files with dates
To: None <netbsd-users@NetBSD.org>
From: Christian Biere <christianbiere@gmx.de>
List: netbsd-users
Date: 02/04/2007 19:04:45
Steven M. Bellovin wrote:
> Jan Danielsson <jan.m.danielsson@gmail.com> wrote:
> > Steven M. Bellovin wrote:
> > > for f in
> > > ~/backup/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].gpg
> >
> > The problem is that I need to process all the files, even those
> > without a date -- it's just that I need to determine if they do
> > contain a date, because they are handled a little differently.
> for i in ~/backup/*
> do
> case `basename $i` in
Use of ${file##*/} looks actually better because it's a shell builtin unlike
basename unless you add this.
basename() {
echo "${1##*/}"
}
I realize handling of /blah/ differs from /usr/bin/basename, doesn't matter
here though. That's more readable at least and lack of readability is IMHO
the real issue with most scripts be it Bourne Shell, Perl or whatever.
> [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].gpg) one variant
I was about to suggest similar
case "$file" in *[1-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]*) ...;;
...
esac
--
Christian