[Gllug] Arithmetic error in bash on 08 and 09?
Holger Duerer
hduerer at gmx.net
Thu Jul 22 11:19:44 UTC 2004
>>>>> "Wulf" == Wulf Forrester-Barker <wulf.f-b at uhl.nhs.uk> writes:
[...]
Wulf> Out of interest, is there a neater way this could be done in
Wulf> a bash script?
Hmmm. What if you just remove the leading 0 before doing the
arithmetic?
Something along the lines of (more general than necessary):
,----
| # Get the number
| num=$(date +%U)
|
| # Remove leading 0s (but not the last one remaining)
| while [ $(expr $num : '0[0-9]') != 0 ]; do
| num=$(expr substr $num 2 1000)
| done
|
| # Increment
| num=$(expr $num + 1)
|
| # Make it a file name:
| Xfile=$(printf XXX%02d.log $num)
`----
Wrap it in a function and your code will still be tidy...
Holger
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list