BASH script bug?, simple maths...
Hi All,
I think i've found a little bug but would love for someone to confirm? Basically I have this script Code:
IN=00:08:19.12 This works on a unix box that I had access to but on the N900 I get the following error Code:
Nokia-N900:/home/user/MyDocs# sh test Thanks jamie UPDATE: I've found that if I set IN to the following it works except for the lines in red italics? how wierd is that? IN=00:00:19.12 IN=00:01:19.12 IN=00:02:19.12 IN=00:03:19.12 IN=00:04:19.12 IN=00:05:19.12 IN=00:06:19.12 IN=00:07:19.12 IN=00:08:19.12 IN=00:09:19.12 IN=00:10:19.12 IN=00:11:19.12 IN=00:12:19.12 IN=00:13:19.12 IN=00:14:19.12 IN=00:15:19.12 IN=00:16:19.12 IN=00:17:19.12 IN=00:18:19.12 IN=00:19:19.12 IN=00:20:19.12 |
Re: BASH script bug?, simple maths...
08
Integers with leading "0" are interpreted as octal, so 08 is an illegal octal number. Remove the leading "0". Nicolai |
Re: BASH script bug?, simple maths...
Quote:
any chance of a code snipet as to how to remove the trailing zero? Or just a better way of doing what I'm doing =) Thanks Jamie |
Re: BASH script bug?, simple maths...
You can use bc to do the maths (you may need to install it)
Code:
a=$(echo "( $a * 60 ) + $x" | bc ) |
Re: BASH script bug?, simple maths...
retsaw, that was perfect, thanks!
|
Re: BASH script bug?, simple maths...
Following on from Nicolai's explanation - an alternative to using bc is to force bash to interpret the value as decimal, thus having the added option of the leading zero being chopped:
Code:
#!/bin/bash |
Re: BASH script bug?, simple maths...
Which while it works with bash, the N900 by default uses the ash shell built in to busybox and it doesn't work with that.
|
Re: BASH script bug?, simple maths...
Quote:
Fair point, well made! Apologies :) |
Re: BASH script bug?, simple maths...
Quote:
|
Re: BASH script bug?, simple maths...
That point hadn't passed me by, but I also noted the error message was from Busybox's Ash shell as Bash gives a slightly different error. But I agree, there's no need for the facepalm, it was a useful post nonetheless and Bash was mentioned in the title.
|
All times are GMT. The time now is 05:30. |
vBulletin® Version 3.8.8