Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nesting a while in a for using bourne shell 1

Status
Not open for further replies.

yesti

MIS
Dec 8, 2000
166
US
is it possible to nest a while in a for using bourne shell to rotate logfiles? The $LOG variable is not changing in the while loop:

N=4
I=`expr $N - 1`
for LOG in log1 log2 log3 ; do
while [ $I -ge 0 ] ; do
test -f $LOG.$I && mv $LOG.$I $LOG.$N
N=$I
I=`expr $I - 1`
done
test -f $LOG && mv && $LOG $LOG.0
cp /dev/null $LOG
chmod 644 $LOG
done
 
Yes indeed:
for LOG in log1 log2 log3 ; do
N=4
I=`expr $N - 1`
while [ $I -ge 0 ] ; do
test -f $LOG.$I && mv $LOG.$I $LOG.$N
N=$I
I=`expr $I - 1`
done
test -f $LOG && mv $LOG $LOG.0
cp /dev/null $LOG
chmod 644 $LOG
done



Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks for pointing out my stupid error. Here I was thinking it was the shell when it was me. Much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top