Bash can seem pretty random and weird at times, but most of what people see as quirks have very logical (if not very good) explanations behind them. This series of posts looks at some of them.
# Why don't the options in "man time" work? time -f %w myapp
Short answer: ‘time’ runs the builtin version, ‘man time’ shows the external version
time
is a builtin in the shell, as well as an external command (this also goes for kill, pwd, and test). The man time
shows info about the external command, while help time
shows the internal one.
To run the external version, one can use command time
or /usr/bin/time
or just \time
.
The reason why time is built in is so timing pipelines will work properly. time true | sleep 10
would say 0 seconds with an external command (which can’t know what it’s being piped into), and while the internal version can say 10 seconds since it knows about the whole pipeline.
POSIX leaves the behaviour of time a | b
undefined.
# This finds the full path to ls. Why isn't there a 'man type'? type -P ls
type is a bash builtin, not an external command. This allows it to take shell functions and aliases into account, something whereis can’t.
Builtins are documented in man bash, or more conveniently, “help type” (help is also a builtin).