Nested If question

if [[ -a ${LOGFILE} ]]; then
if [[ -a ${LOGFILE}.old ]]; then
rm -f ${LOGFILE}.old
fi
mv ${LOGFILE} ${LOGFILE}.old
fi

Havent done nested ifs in a while. I'm reading someones code If I'm reading this correctly. It checks for the logfile, and if it exists it checks for the old logfile and if that exists, it removes the old log file. Else it moves the logfile to the logfile.old. Someone correct me if I'm wrong, thanks.

You have it right. Except the -a should maybe be a -f because -a means "and" which makes no sense in what you posted

Not my code, just a copy and paste. But I was wondering what the -a meant. I guess the -f means file. Thanks.

See the man page for test -- man test
it has all of those -<whatever> tests and tells you their meaning. -f tells you if it is a regular file and exists, for example.

not exactly - it will 'move the logfile to the logfile.old' regardLESS whether the 'old logfile' exists or not - there is no 'ELSE' in the inner 'if'.

Then this makes less sense. Wouldnt the move overwrite whats there if the old one exists anyway? I dont see the reason for the remove then.

what about this- is this what u r looking for?

if [[ -s ${LOGFILE} ]] && [[ [[ -s ${LOGFILE}.old ]]; then
rm -f ${LOGFILE}.old
mv ${LOGFILE} ${LOGFILE}.old
fi

cheers,
Devaraj Takhellambam

not if you didn't specify 'mv -f'
'man mv' yields:

     -f      Do not prompt for confirmation before overwriting the destination
             path.  (The -f option overrides any previous -i or -n options.)

somewhat ugly coding, if you ask me.....

./a.sh[1]: syntax error: `[[' missing expression operator

why do you have to check BOTH conditions?
why do you have to delete .old?
why cannot you just mv 'new' to 'old' if 'new' exists?