It is usual to do time cmd
for many types of cmd
(s) in bash:
$ time true
real 0m0.000s
user 0m0.000s
sys 0m0.000s
The output format could be changed (even to a posix format with time -p):
$ TIMEFORMAT='real %R'; time true
real 0.000
But zsh doesn't report the time for simple commands (try also time echo
):
% time true
Converting the command to a pipe reports other things:
$ zsh -c 'time echo yes | cat'
yes
echo yes 0.00s user 0.00s system 26% cpu 0.001 total
cat 0.00s user 0.00s system 85% cpu 0.002 total
The shell could be forced to give a time output with a subshell (…)
:
$ zsh -c 'time ( true )'
( true; ) 0.00s user 0.00s system 26% cpu 0.005 total
But that doesn't work with {…}
, nor with builtins like for
:
$ zsh -c 'time { for i in $(seq 100); do ls; done >/dev/null; }'
How could zsh's time made to accept simple commands without a subshell.
Or, an even simpler question:
Is there a way to write code that works in ksh, bash,zsh with the time keyword?