在shell有哪些呢" 2 - ;&放大器1 QUOT;意思? [英] In the shell, what does " 2>&1 " mean?

查看:142
本文介绍了在shell有哪些呢" 2 - ;&放大器1 QUOT;意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Unix外壳,如果我想结合标准错误标准输出为进一步操作标准输出流,我可以追加我的命令的末尾以下内容:

In a Unix shell, if I want to combine stderr and stdout into the stdout stream for further manipulation, I can append the following on the end of my command:

2>&1

所以,如果我想使用从克输出头+ +,我可以做这样的事情:

So, if I want to use "head" on the output from g++, I can do something like this:

g++ lots_of_errors 2>&1 | head

所以我只能看到前几个错误。

so I can see only the first few errors.

我总是很难记住这一点,我经常得去看看它,它主要是因为我不完全理解这个特殊的伎俩的语法。有人可以打破这种并通过字符解释字符是什么2>&安培; 1?指

I always have trouble remembering this, and I constantly have to go look it up, and it is mainly because I don't fully understand the syntax of this particular trick. Can someone break this up and explain character by character what "2>&1" means?

推荐答案

文件描述符1是标准输出(stdout)。结果
文件描述符2是标准错误(错误)。

File descriptor 1 is the standard output (stdout).
File descriptor 2 is the standard error (stderr).

下面是要记住这个结构(尽管它并不完全准确)的一种方法:首先, 2→1 可能看起来像标准错误重定向到标准输出的好办法。但是,它实际上是作为PTED间$ P $标准错误重定向到一个名为 1 文件。 &安培; 表示接下来是文件描述符,而不是文件名。因此,结构变为: 2 - ;&放大器; 1

Here is one way to remember this construct (although it is not entirely accurate): at first, 2>1 may look like a good way to redirect stderr to stdout. However, it will actually be interpreted as "redirect stderr to a file named 1". & indicates that what follows is a file descriptor and not a filename. So the construct becomes: 2>&1.

这篇关于在shell有哪些呢" 2 - ;&放大器1 QUOT;意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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