maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Nokia N900 (https://talk.maemo.org/forumdisplay.php?f=44)
-   -   BASH script bug?, simple maths... (https://talk.maemo.org/showthread.php?t=83923)

lma 2012-04-27 19:43

Re: BASH script bug?, simple maths...
 
Quote:

Originally Posted by jamiefuller (Post 1198255)
any chance of a code snipet as to how to remove the trailing zero?

You can use a pattern expansion:
Code:

a=$(( ( a * 60) + ${x#0} ))
Quote:

Or just a better way of doing what I'm doing =)
No forks, and unrolling the loop for simplicity:

Code:

IN=00:08:19.12
IFS=: read h m s <<EOF
${IN%%.*}
EOF

a=$(( ${h#0} * 3600 + ${m#0} * 60 + ${s#0} ))

Quick'n'dirty hack (ab)using date:

Code:

date -u -d 1970.01.01-${IN%%.*} +%s
(Note: the input date format is highly non-portable)


All times are GMT. The time now is 09:30.

vBulletin® Version 3.8.8