Subject: Re: Shell hack -- getting files with dates
To: Jan Danielsson <jan.m.danielsson@gmail.com>
From: Steven M. Bellovin <smb@cs.columbia.edu>
List: netbsd-users
Date: 02/03/2007 17:46:59
On Sat, 03 Feb 2007 23:10:06 +0100
Jan Danielsson <jan.m.danielsson@gmail.com> wrote:

> Hello,
> 
>    I am processing a list of files using a for loop. However -- I
> would like to perform some special processing if the file names
> contain a date. I wrote this:
> 
> -----------------------------
> #!/bin/sh
> 
> for f in ~/backup/*.gpg
> do
>         if echo "$f" | egrep -q '[0-9]{4}-[0-9]{2}-[0-9]{2}' ; then
>                 echo "$f"
>         fi
> 
> done
> -----------------------------
> 
>    ...and it seems to do what I expect it to. What I am actually using
> is the return code from egrep -- but is it safe to do it like that? Is
> my assumption correct -- that the return code from egrep is simply
> "passed through" echo, or will I be seeing odd side effects five years
> from now?
> 
The return code from egrep is specified by Posix, as I recall.  However
-- why not do

	for f in ~/backup/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].gpg




		--Steve Bellovin, http://www.cs.columbia.edu/~smb