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)
|