Save in a variable the number of seconds a process took to run

后端 未结 5 673
走了就别回头了
走了就别回头了 2021-02-04 17:15

I want to run a process in bash and save in an env variable the number of seconds it took to run. How would I do such a thing?

5条回答
  •  别跟我提以往
    2021-02-04 18:00

    Use the time command. Note that the bash version of time is not the same as /usr/bin/time. So you would have something like:

    TIME=`/usr/bin/time --format="%e" your_command_here >/dev/null`
    

    The format just pulls the "real" time value out. You would need to convert that from a string if you wanted to do anything more than display it.

    If you just want to export the string, use export.

提交回复
热议问题