On Monday 10 December 2007 18:34, Carlos E. R. wrote:
> Hi,
>
> I have a bash script with this line:
>
> DIFF=$[ ($LOC_H - $HWC_H)*3600 + ($LOC_M - $HWC_M)*60 + ($LOC_S -
> $HWC_S) ]
>
> to calculate a time difference in seconds. Well, when the seconds are
> "08" it fails:

As Carl mentioned, BASH acts like the C and C++ compilers in that a 
leading 0 signifies octal (base 8) numeric literals and a 0x prefix 
signifies hexadecimal (base 16).

You say you're doing temporal math. You might want to look at 
whether "date" makes this easier for you. It can do some temporal math.

Also, when the math required in shell scripts gets more than a little 
complicated, I usually switch to "dc". It's very flexible, though it 
uses reverse polish notation, so you have to either like HP calculators 
(I do) or learn to readjust your thinking about how you express 
arithmetic expressions.

...

Oh, all right. I should mention "bc," too. It does infix. If you're into 
that sort of thing.


Both have good man pages.


Randall Schulz
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to