The difference in the output format of the time command in your examples is due to how time is being invoked and which version of time is being used in each case.
time echo -nIn this case, time is a shell builtin (likely from bash). The output format is:
textreal 0m0.000s user 0m0.000s sys 0m0.000s
This is the default format for the bash builtin time command.
echo | time echo -nHere, time is not a shell builtin but the external /usr/bin/time command. The output format is more detailed:
text0.00user 0.00system 0:00.00elapsed 100%CPU (0avgtext+0avgdata 1804maxresident)k 0inputs+0outputs (0major+99minor)pagefaults 0swaps
This is the output of the GNU time command (/usr/bin/time), which provides additional metrics like memory usage, I/O, and page faults.
Shell Builtin vs. External Command:
time echo -n, bash uses its builtin time command.echo | time echo -n, the shell interprets time as the external /usr/bin/time command because the pipe (|) forces the shell to look for an external executable.Different Implementations:
bash builtin time is simpler and only reports real, user, and sys times./usr/bin/time (GNU time) provides a more detailed breakdown of resource usage.If you want to use the external /usr/bin/time explicitly, you can call it directly:
bash/usr/bin/time echo -n
This will give you the detailed output even without a pipe.
Alternatively, if you want to use the bash builtin time in the second case, you can use:
bashecho | bash -c "time echo -n"
time echo -nreal, user, sys/usr/bin/timeVibe can make mistakes. Check answers. Learn more