Redirect Problem

I am using the time command in a script however the output of the time command will display on my screen but not my output file. Any Ideas on how to fix this?

> cat test.sh
#############################
#!/usr/bin/sh

for COMMAND in pwd
do
time ${COMMAND}
done | sed "s/^/ /g" | tee -a test.out
#############################

> test.sh

real 0m0.00s
user 0m0.00s
sys 0m0.00s
/tmp

> cat test.out
/tmp

#!/usr/bin/sh

for COMMAND in pwd
do
time ${COMMAND} | sed "s/^/ /g" | tee -a test.out
done

cheers,
Devaraj Takhellambam

The time command output its information to stderr, not stdout so you would need to redirect stderr.

#!/usr/bin/sh

for COMMAND in pwd
do
time ${COMMAND}
done 2>&1 | sed "s/^/ /g" | tee -a test.out

devtakh that didn't seem to do any different.

reborg that did work. i thought i tired this early as "done | sed "s/^/ /g" | tee -a test.out 2>&1" but it didnt seem to work for me. thanks for your help.

gotcha...
since time command doesn't display on stdout..
2>&1 does the trick..thats great.
so you can play around with 2>&1..redirecting stderr to stdout and then do whatever you may want..

cheers,
Devaraj Takhellambam