On Fri, 13 Dec 2002, Ashley M. Kirchner wrote:

> 
>     Theoretically, in my head, this ought to function, however I wanted 
> to run it past by some of the shell guru's on here, see if anyone spots 
> any logistical problems with this.  I'm trying to run a particular 
> command several time (it's a backup script, using cp/rsync).  First, the 
> script renames the old hierarchy of directories then performs the actual 
> backup.  So, you're looking at something like this:
> 
> if [ -d $SNAPSHOT/daily.5 ] ; then                               \
>   $MV $SNAPSHOT/daily.5 $SNAPSHOT/daily.6 ;                      \
> fi;

first, you should delete the .6 directory, otherwise the .5
directory will be copied as  *subdirectory* of .6.

> if [ -d $SNAPSHOT/daily.4 ] ; then                               \
>   $MV $SNAPSHOT/daily.4 $SNAPSHOT/daily.5 ;                      \
> fi;
> if [ -d $SNAPSHOT/daily.3 ] ; then                               \  
>   $MV $SNAPSHOT/daily.3 $SNAPSHOT/daily.4 ;                      \
> fi;
> if [ -d $SNAPSHOT/daily.2 ] ; then                               \
>   $MV $SNAPSHOT/daily.2 $SNAPSHOT/daily.3 ;                      \
> fi;
> if [ -d $SNAPSHOT/daily.1 ] ; then                               \ 
>   $MV $SNAPSHOT/daily.1 $SNAPSHOT/daily.2 ;                      \
> fi;
> 
> 
>     My question is, can I shorten this with a FOR loop:
> 
> for idx in 5 4 3 2 1 ; do                                        \
>   if [ -d $SNAPSHOT/daily.$idx ] ; then                          \
>     $MV $SNAPSHOT/daily.$idx $SNAPSHOT/daily.`expr $idx + 1` ;   \
>   fi;
> done

sure, but why use expr?  why not just use the arithmetic built
into bash, as in $SNAPSHOT/daily.$((idx+1)) ??

rday



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to