time
is many things. There's the external /usr/bin/time
GNU program. There's the bash keyword time
.
$ type -a time
time is a shell keyword
time is /usr/bin/time
When you run time …
in an interactive shell, you'd be typically using bash, and so the time
keyword takes effect.
When you run time …
in a script using /bin/sh
, the shell used (dash
)
doesn't have time
as a keyword, and the external time
command is called.
To get the output you want, call the external time
command with the -p
option:
-p, --portability
Use the following format string, for conformance with POSIX
standard 1003.2:
real %e
user %U
sys %S
The external command is also more friendly. Since it isn't a keyword, you don't need to do the wrap-in-{ … }
-for-redirection trick to get the output in a file. There's an option for that:
-o FILE, --output=FILE
Write the resource use statistics to FILE instead of to the
standard error stream. By default, this overwrites the file,
destroying the file's previous contents. This option is useful
for collecting information on interactive programs and programs
that produce output on the standard error stream.
The output is also far more customizable, making it easier for processing later on. With bash's time
, the options provided in TIMEFORMAT
are very limited.
Best Answer
Here's a fish...