Shell execution: time vs. /usr/bin/time
time
is builtin in both zsh and bash. However, which
is only built-in to zsh. In bash, when you use which
it runs /usr/bin/which
which has no idea about shell built-ins.
So in bash, you should use:
$ type timetime is a shell keyword
The reason time -l ...
doesn't work is that the time
syntax doesn't include the -l
flag.
In both cases, it's not really correct to say that time
is a built-in function. Calling it a "reserved word" or "shell keyword" is more accurate, because it applies to an entire pipeline; it cannot be implemented as a function or external command. In that sense, it is similar to other syntactic elements like if
and while
.
Another way to know whether a command is a bash builtin command is to use the help
builtin command. The side effect is to get the information about said command (and supported command line arguments.)
bash$ help timeReport time consumed by pipeline's execution.Execute PIPELINE and print a summary of the real time, user CPU time,and system CPU time spent executing PIPELINE when it terminates.Options: -p print the timing summary in the portable Posix formatThe value of the TIMEFORMAT variable is used as the output format.Exit Status:The return status is the return status of PIPELINE.
For non-builtin commands, help
says it does not know about it.
bash$ help lsbash: help: no help topics match `ls'. Try `help help' or `man -k ls' or `info ls'.
time is a builtin function in zsh. It is not in bash. If you want to use the /usr/bin/time version you need to supply the full path when using zsh.
It is also possible to disable this behavior using the "disable -r" command in zsh.