This question already has an answer here:
I want to run some executables with the time command
time myexec -args
How can I store only the time output to a variable in bash? Thats the only part I care about for this script, not the output of the executable. Is there a way to get that value, or will I have to parse the text of the entire command?
See BashFAQ/032.
All output (stdout, stderr and
time
) captured in a variable:Output to stdout and stderr go to their normal places:
Something like this?
BASH has its built-in variant of
time
. If you do aman time
you will find that a lot of those option listed there won't work withtime
command. The man page warns BASH users that they may use explicit path totime
.The explicit path is
/usr/bin/time
on Ubuntu, but you can find it out with$ which time
.With the proper path, you can use the
-f
or--format
option and a lot of formatting parameters that will nicely format your result which you can store to a variable as well.Actually, I found this as well - How to store a substring of the output of "time" function in bash script
Probably closer to what I was looking for