Bash Script
Tony Arnold
tony.arnold at manchester.ac.uk
Tue Oct 24 17:00:22 UTC 2006
Karl,
On Tue, 2006-10-24 at 23:11 +1000, Karl Auer wrote:
> On Tue, 2006-10-24 at 13:38 +0100, Tony Arnold wrote:
> > > Good call, but the code is still broken, because the problem was not
> > > only with printf, but also with the expansion of $Num in "Num=$((Num
> > > +1));"
> >
> > Why is this broken in my version? $Num never gets leading zeros with my
> > code, so far as I can see, although I no longer have the original, so I
> > could be missing something.
>
> Did you make your suggested change and run the script ten times?
I have to admit I did not.
> Then I applied your changes and tried again. The same symptoms on the
> tenth loop! Why? Because 07 (octal) plus 1 is 8 (decimal). When $Num is
> 07, the addition (correctly) gives 8, but the next time around, that 8
> comes from a directory prefix and looks like "08". It is *presented*
> that way in the addition. The addition fails, seeing an invalid octal
> number, so $Num still contains "08". That's what printf then sees, and
> printf complains for the same reason.
OK, I understand. I've just looked at the original again on Gmane and
you are, of course, quite right.
I should really test code before posting!
Regards,
Tony.
--
Tony Arnold, IT Security Coordinator, University of Manchester,
IT Services Division, Kilburn Building, Oxford Road, Manchester M13 9PL.
T: +44 (0)161 275 6093, F: +44 (0)870 136 1004, M: +44 (0)773 330 0039
E: tony.arnold at manchester.ac.uk, H: http://www.man.ac.uk/Tony.Arnold
More information about the ubuntu-users
mailing list