是在使用 `time` bash 命令时保存在文件中并格式化测量的实时时间的更短方法

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

我想使用time bash命令来测量脚本的执行时间,并且只将实时时间保存在一个文件中,具有特定的精度。这是我的作品:

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

但我想知道是否有更短的方法,或者是否可以使用 tee?

Is a shorter way of saving

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

是的,只需删除 space 和不需要的引号。此外,由于 subshel​​l 很可能不是问题,您可以将 { 更改为 ( 以在 { 之后和 }.[=16 之后保存所需的 space =]

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

如果我没记错的话,少了 8 个字符。