views:

35

answers:

4

I would like to make a script that outputs only the real time value from the time command so I can plot the results. For example time command outputs

real    1m0.001s
user    1m0.000s
sys  0m0.001s

I want to write a script that outputs

60.001 

How do I get just real time value from 'time' command in seconds?

+2  A: 

BASH FAQ entry #32

Ignacio Vazquez-Abrams
+3  A: 

According to man time, the following should work:

time -f "%e" command

EDIT: call the time command with its path:

$ /usr/bin/time -f "%e" sleep 5

5.00

Without the path, it was using some bash's equivalent. With the path, it works for me.

eumiro
I'm sorry, I am on a mac, and that outputs bash: -f: command not found
Matthew Sowders
EDIT: works with /usr/bin/time
eumiro
A: 

Alternatively, use /usr/bin/time or take a look at the similar question
Using time command in bash script.

Archimedix
+1  A: 

If you're using the Bash builtin time, set the TIMEFORMAT variable to %R:

$ TIMEFORMAT=%R
$ time sleep 1
1.022
Dennis Williamson