On 19:59 13 Dec 2002, Ashley M. Kirchner <[EMAIL PROTECTED]> 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;
| 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

Certainly.
BTW, you don't need all though sloshes, unless this came from a Makefile
(which I doubt because then there'd be lots of doubled $$s floating
around).

Eg:

        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

Cheers,
-- 
Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/

... common sense can be the first victim of a genuine and often ardent desire
to improve the way things are done.  Unfortunately, once common sense is
missing there is no limit to the damage that can unwittingly be done.
        - Bjarne Stroustrup



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

Reply via email to