Search code examples
bashtimeexecution-time

Is a shorter way of saving in a file and formatting the measured real time when using the `time` bash command


I want to use the time bash command to measure the execution time of a script, and to save only the real time in a file, with a specific precision. Here is what I have that works:

{ time TIMEFORMAT='%4R' <script> 2> <script>.stderr ; } 2>> time.txt

But I'm wondering whether there is a shorter way of doing this, or is it possible to use tee?


Solution

  • Is a shorter way of saving

    I'm wondering whether there is a shorter way of doing this

    Yes, just remove the spaces and unneeded quotes. Also, as subshell is most probably not a problem, you can change { for ( to save needed space after { and after }.

    (TIMEFORMAT=%4R time cmd 2>cmd.stderr)2>>time.txt
    

    It is, if I'm counting right, 8 characters shorter.