I have a nice bit of code to convert hh:mm:ss into seconds like this:
Code:
jonke@charlie:~$ echo "1:01:0" | sed -E 's/(.*):(.+):(.+)/\1*3600+\2*60+\3/;s/(.+):(.+)/\1*60+\2/' | bc
3660
jonke@charlie:~$
Converts one hour and one minute into seconds.
How can I assign this to a variable?
I've tried:
Code:
jonke@charlie:~$ ST="1:01:0" | sed -E 's/(.*):(.+):(.+)/\1*3600+\2*60+\3/;s/(.+):(.+)/\1*60+\2/' | bc
jonke@charlie:~$ echo $ST
10:01
jonke@charlie:~$ ST=$("1:01:0" | sed -E 's/(.*):(.+):(.+)/\1*3600+\2*60+\3/;s/(.+):(.+)/\1*60+\2/' | bc)
bash: 1:01:0: command not found
jonke@charlie:~$
and I've tried other variations of this with no luck, it must be very simple, but I'm missing the point!