Article 5J5VA [SOLVED] Bash: Assign output of a command to a variable

[SOLVED] Bash: Assign output of a command to a variable

by
GPGAgent
from LinuxQuestions.org on (#5J5VA)
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!latest?d=yIl2AUoC8zA latest?i=8jHPQOKQ74k:sL4gE_5aBjY:F7zBnMy latest?i=8jHPQOKQ74k:sL4gE_5aBjY:V_sGLiP latest?d=qj6IDK7rITs latest?i=8jHPQOKQ74k:sL4gE_5aBjY:gIN9vFw8jHPQOKQ74k
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments