bash 'time' function

Soren Jacobsen devsoren at
Fri Dec 21 00:42:47 PST 2001

On Fri, Dec 21, 2001 at 01:26:26AM -0500, Chris F.A. Johnson wrote:
> On Thu, 20 Dec 2001, Soren Jacobsen wrote:
> No, I am redirecting stderr, and using process substitution.

Neat, I didn't know about that.

> > soren:~$ { time ls -R /usr/local &>/dev/null; } 2>&1 | grep sys
> > sys     0m0.600s
> If the command sends anything to stdout, this will lose it, or give
> unwanted output if it happens to contain the string "sys".

It is supposed to lose the output, that's why &>/dev/null is there, so
grep doesn't get anything other than what it's supposed to. 

test.c is:

#include <stdio.h>
fprintf(stdout, "standard output. blef.\n");
fprintf(stderr, "standard error. sys.\n");

soren:~$ ./test
standard output. blef.
standard error. sys.

# to show time outputs to stderr
soren:~$ { time ./test &>/dev/null; } 1>/dev/null

real    0m0.005s
user    0m0.010s
sys     0m0.000s

# send stderr to stdout and grep it.
soren:~$ { time ./test &>/dev/null; } 2>&1 | grep sys
sys     0m0.000s


Sure, $TIMEFORMAT is easier, and you could just as easily use 2> >( grep
sys ) where I redirected stderr to stdout and piped, that's more of a
matter of choice I guess. Gotta stand by my method, though. :p

|<')                |
|(__) Soren Jacobsen|
|^  ^               |

Unsubscribe: send email to listar at
and put 'unsubscribe blfs-support' in the subject header of the message

More information about the blfs-support mailing list