Shell scripts use Duck Typing.
http://en.wikipedia.org/wi
Basically, if it looks like a duck, smells like a duck and sounds like a duck it probably is a duck!
So, the type of the variable is inferred based upon how you use it. This is why bash has different predicate operators for testing (for example) equality and inequality on strings and integers. Use a string type operator and bash will assume it's a string, likewise for number operators. Of course, if you try to use a number operator on a string type that cannot possibly be inferred as a number bash will complain!
In your example, ((dateday=dateday-1)), you are treating dateday as a string so bash then complains when you try to perform maths with it. You might be able to convince it otherwise if you use -eq instead.
If, like me, you come from a strongly typed background (C++) it can take a while to get used to, but it's not all bad :)
STRING1 = STRING2
the strings are equal
STRING1 != STRING2
the strings are not equal
INTEGER1 -eq INTEGER2
INTEGER1 is equal to INTEGER2
INTEGER1 -ne INTEGER2
INTEGER1 is not equal to INTEGER2
I hope this helps to clarify for you.
-Rx.
Main Topics
Browse All Topics





by: ozoPosted on 2007-12-10 at 13:47:19ID: 20445531
It shouldn't matter