[Gllug] Arithmetic error in bash on 08 and 09?
Wulf Forrester-Barker
wulf.f-b at uhl.nhs.uk
Thu Jul 22 09:15:01 UTC 2004
Rich <rich at annexia.org> replied:
> 08 is an invalid octal number. You need to change the script to
> remove the preceeding zero, so you're calculating in decimals.
09 as well. I've got a scripted routine on one of my boxes that ran into
exactly the same problem, calculating a log file name which was in the
format XXX[week of year + 1].log.
Of course, because it's based on the week of the year, the system ran
smoothly for several months before this bug reared its ugly head.
Fortunately I got onto it right away otherwise the symptoms might have
disappeared before I became any the wiser.
Originally, I'd been using:
Xfile="XXX$(( $(date +%U)+1 )).log"
This has now been patched to:
if [ $(date +%U) = "08" ]; then
Xfile="XXX9.log"
elif [ $(date +%U) = "09" ]; then
Xfile="XXX10.log"
else
Xfile="XXX$(( $(date +%U)+1 )).log"
fi
It's not incredibly elegant but, along with a nice fat comment, it
serves to keep the issue in mind next time I do something that might be
affected.
Out of interest, is there a neater way this could be done in a bash
script?
Wulf
--
Wulf Forrester-Barker, webmaster
http://www.lewisham.nhs.uk/
wulf.f-b at uhl.nhs.uk
**********************************************************************
DISCLAIMER:
Any opinions expressed in this email are those of the individual and
not necessarily the Trust. This email and any files transmitted with
it are confidential and intended solely for the use of the individual
or entity to whom they are addressed. Any unauthorised disclosure of
the information contained in this email is strictly prohibited.
The contents of this email may contain software viruses which could
damage your own computer system. Whilst we have taken every
reasonable precaution to minimise this risk, we cannot accept liability
for any damage which you sustain as a result of software viruses.
You should therefore carry out your own virus checks before opening
the attachment.
If you have received this email in error please notify the sender or
postmaster at uhl.nhs.uk. Please then delete this email.
University Hospital Lewisham
Tel: 020 8333 3000
Web: http://www.lewisham.nhs.uk/
**********************************************************************
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list