Zsh – Why time echo Command Produces No Output

oh-my-zshtimezsh

I'm using Mac, and I'm trying to time the command execution.

If I do

time echo

it doesn't have any output

But If I do

time ls

it does give me the output of time function

Any idea why that happens?

Update: turns out it's cuz I'm using zsh, with oh-my-zsh installed. It works well in bash, but no output in zsh. Any idea why?

Best Answer

In zsh, the time keyword has no effect on builtins (or other similar shell-internal constructs). From this mailing list post:

Additional note: The time builtin applied to any construct that is executed in the current shell, is silently ignored. So although it's syntactically OK to put an opening curly or a repeat-loop or the like immediately after the time keyword, you'll get no timing statistics. You have to use parens instead, to force a subshell, which is then timed.

$ time echo

$ time (echo)

( echo; )  0.00s user 0.00s system 51% cpu 0.001 total
Related Question