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


--
W | I haven't lost my mind; it's backed up on tape somewhere.
+--------------------------------------------------------------------
Ashley M. Kirchner <mailto:[EMAIL PROTECTED]> . 303.442.6410 x130
IT Director / SysAdmin / WebSmith . 800.441.3873 x130
Photo Craft Laboratories, Inc. . 3550 Arapahoe Ave. #6
http://www.pcraft.com ..... . . . Boulder, CO 80303, U.S.A.





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

Reply via email to