如何将stderr和stdout重定向到脚本同一行中的不同文件? [英] How to redirect stderr and stdout to different files in the same line in script?

查看:65
本文介绍了如何将stderr和stdout重定向到脚本同一行中的不同文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很了解:

$ command 2>> error

$ command 1>> output

有什么办法可以将stderr输出到错误文件,并在bash的同一行中将stdout输出到输出文件?

Is there any way I can output the stderr to the error file and output stdout to the output file in the same line of bash?

推荐答案

只需将它们添加到一行command 2>> error 1>> output

Just add them in one line command 2>> error 1>> output

但是,请注意,如果文件已包含数据,则>>用于追加.而>将覆盖文件中的所有现有数据.

However, note that >> is for appending if the file already has data. Whereas, > will overwrite any existing data in the file.

因此,如果您不想附加command 2> error 1> output.

So, command 2> error 1> output if you do not want to append.

为完成起见,您可以将1>编写为>,因为默认文件描述符是输出.所以1>>是同一件事.

Just for completion's sake, you can write 1> as just > since the default file descriptor is the output. so 1> and > is the same thing.

所以command 2> error 1> output变为command 2> error > output

这篇关于如何将stderr和stdout重定向到脚本同一行中的不同文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆