1

I imagine time A | B would only measure the time taken to run A (since the argument to time is A). What's the solution ?

2

Depends on the shell. e.g. Bash has a keyword time that times the whole pipeline. An external implementation of time would only time A in your example. A workaround might be to explicitly run an extra shell:

time sh -c "A | B"
  • Technically time is not a builtin, but a keyword (in bash, and in ksh and zsh which have the same feature). It has to be so that time applies to the following compound command and not just to a simple command. – Gilles 'SO- stop being evil' Jul 11 '17 at 23:42
0

You could also use a subshell, e.g.

 time ( A | B )

at least when time is the bash builtin (but then a subshell is useless). If you want to use the time(1) command (see this) you'll better explicitly run some sh -c like answered by iikkachu

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.