time seems to work generally on my system:
ā ~ time touch tmp.txt
touch tmp.txt 0.00s user 0.00s system 54% cpu 0.007 total
Yet its output seems to get suppressed when I attempt to time echo.
ā ~ time echo š
š
And to thicken the plot: it seems to recover its ability to measure echo, provided I throw that echo into a pipeline:
ā ~ time echo š | xxd
00000000: f09f 8d94 0a .....
echo š 0.00s user 0.00s system 38% cpu 0.002 total
xxd 0.00s user 0.00s system 88% cpu 0.003 total
What's going on? Is echo outputting to time's favourite stream, replacing its report?
Bonus points for: is there some way (e.g. stream redirection) to make time echo š output the usual report?
Edit: Some commenters have pointed out that I am using zsh. I'd not noticed that at the time, but that explains a lot.
bash uses normal executables to do time and echo.
bash-3.2$ which echo
/usr/local/opt/coreutils/libexec/gnubin/echo
bash-3.2$ which time
/usr/bin/time
(Looks like I am using a GNU version of echo rather than the presumably BSD one, /bin/echo, that comes with Mac OS X).
Whereas zsh provides something significantly more special:
ā ~ which echo
echo: shell built-in command
ā ~ which time
time: shell reserved word
Neither of these are normal executables. Very interesting!
This seems to happen when you use the built-in time (which measures a complete pipeline) combined with another built-in command, like echo, true.
Curiously, I could not find any mention of this in the zshall man page.
To work around it, run this:
time command echo š
The command precommand modifier invokes the external echo instead of the built-in one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With