Avah
Avah

Reputation: 227

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?

Upvotes: 0

Views: 33

Answers (1)

KamilCuk
KamilCuk

Reputation: 141523

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.

Upvotes: 1

Related Questions