[英]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.txt文件中,因为这是我的脚本所需的。
(time echo "hi") > time.txt
What I observed is output of time
command is going to terminal. 我观察到的是
time
命令的输出将到达终端。
real 0m0.000s
user 0m0.000s
sys 0m0.000s
and output of echo command is redirected to time.txt 和echo命令的输出重定向到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 ? 如何将
time
命令的输出重定向到文件?
I'm using ubuntu14.04 in case it matters. 我正在使用ubuntu14.04以防万一。
In Is there a way to redirect time output to file in Linux there is one answer which redirects EVERYTHING to time.txt
. 在Linux中是否可以将时间输出重定向到文件,有一个答案可以将EVERYTHING重定向到
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
. 但就我而言,我只希望
time.txt
仅包含time
命令的输出, time.txt
包含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: 如在Linux中是否有一种方法可以将时间输出重定向到文件 ,您需要使用:
{ time echo "hi" ; } 2> time.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.