Subject: Re: Shell hack -- getting files with dates
To: Jan Danielsson <jan.m.danielsson@gmail.com>
From: Simon Burge <simonb@NetBSD.org>
List: netbsd-users
Date: 02/05/2007 04:51:44
Jan Danielsson wrote:

> Steven M. Bellovin wrote:
> [---]
> > The return code from egrep is specified by Posix, as I recall.
> 
>    Excellent.
> 
> >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
> 
> [ ... ]
> 
> #
> # Now, encrypt all the relevant files
> #
> for file in $SRC/system/*.bz2
> do
>    do_enc=3D1
>    tgtfile=3D$SDST/${file##*/}.gpg
>    if echo "$file" | egrep -q '[0-9]{4}-[0-9]{2}-[0-9]{2}' ; then
>       # it is a dated file
>       echo "Target $tgtfile is a dated file.."
>       if [ -f "$tgtfile" ] ; then
>          # target file exists
>          echo "Target $tgtfile exists.."
>          do_enc=3D0
>       fi
>    fi
>    if [ $do_enc -ne 0 ] ; then
>       echo "Encrypting $file to $tgtfile"
>       nice -n 20 /usr/pkg/bin/gpg -r $RCP --encrypt -o - $file > $tgtfile=
> 
>    fi
> done
> -------------------------------------------

What about using sh(1)'s "case"?

	for file in $SRC/system/*.bz2
	do
	   ...
	   case "$file" in
	     *[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]*)
		# it is a dated file
		...
		;;
	   esac
	   ...
	done

?  But then, if the example you posted works, just be happy with that :-)

Cheers,
Simon.