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

前端 未结 4 1056
故里飘歌
故里飘歌 2020-12-13 12:34

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

         


        
相关标签:
4条回答
  • 2020-12-13 13:07

    If you write \time you enforce not to use the bash built in time. So with \time -f '%e' command you are done.

    0 讨论(0)
  • 2020-12-13 13:10

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

    0 讨论(0)
  • 2020-12-13 13:16

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

    $ TIMEFORMAT=%R
    $ time sleep 1
    1.022
    
    0 讨论(0)
  • 2020-12-13 13:19

    time can take an optional --format or -f parameter, but you have to use the full path to the time command, /usr/bin/time

    /usr/bin/time -f "%e" sleep 3
    
    3.00
    

    Without the path, it'll use the time command of the shell which just treats all arguments as the command, so you'll get an -f: command not found.

    0 讨论(0)
提交回复
热议问题