2

I'm on Ubuntu.

Running time seems to output its result to something other than STDOUT or STDERR. Here's why I think so:

[siminm@amide ~]$ time echo hi
hi

real    0m0.000s
user    0m0.000s
sys 0m0.000s
[siminm@amide ~]$ time echo hi >/dev/null 

real    0m0.000s
user    0m0.000s
sys 0m0.000s
[siminm@amide ~]$ time echo hi 2>/dev/null 
hi

real    0m0.000s
user    0m0.000s
sys 0m0.000s
[siminm@amide ~]$ time echo hi 2>&1 >/dev/null 

real    0m0.000s
user    0m0.000s
sys 0m0.000s
[siminm@amide ~]$ time echo hi &>/dev/null 

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

HOWEVER

[siminm@amide ~]$ /usr/bin/time echo hi 2>/dev/null 
hi

3 Answers 3

2

Your shell, which is probably bash, provides a builtin command time. There is also a separate program called time in /usr/bin/, which is in your $PATH. The behavior of the two is different. If you want consistency across all configurations, you should use the program /usr/bin/time instead of the bash builtin time.

3
  • When I run which time it returns /usr/bin/time
    – Mikhail
    Apr 29, 2011 at 20:43
  • @Mikhail, what does type -a time tell you? Apr 29, 2011 at 23:22
  • @glenn, time is a shell keyword time is /usr/bin/time -- this is rather self explanatory now. thanks!
    – Mikhail
    Apr 30, 2011 at 23:26
1

You are always only redirecting the output of your command. Since time writes to stderr try the following:

(time ls >> /stdout/output/of/ls 2>> /stderr/output/of/ls) 2>> /output/of/time
1
  • This is great! I had no idea you can wrap functions in parenthesis like that
    – Mikhail
    Apr 30, 2011 at 23:27
1

"time" builtin output goes to what stderr points to before redirections do happen.

Any non builtin command like /usr/bin/time cannot override the redirection as they happen before it is launched so its output goes to stderr.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .