简体   繁体   中英

Strange behaviour of indirection operator > in bash

I was trying to do this to dump all the output from command line to time.txt file as it is needed for my script.

(time echo "hi") > time.txt

What I observed is output of time command is going to terminal.

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

and output of echo command is redirected to time.txt

$ cat time.txt
$ hi

Why is it so ? I'm having hard time to understand this. How can I redirect output of time command to a file ?

I'm using ubuntu14.04 in case it matters.

In Is there a way to redirect time output to file in Linux there is one answer which redirects EVERYTHING to time.txt .

But in my case I just want time.txt to contain just the output of the time command, NOT the output of the echo .

Not very sure why this post got reopened .

As seen in Is there a way to redirect time output to file in Linux , you need to use:

{ time echo "hi" ; } 2> time.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM