2>是什么?在Unix命令行上是什么意思? [英] What does the 2> mean on the Unix command-line?

查看:71
本文介绍了2>是什么?在Unix命令行上是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

scriptlist=`ls $directory_/fallback_* 2> /dev/null`

该命令的2>部分的目的是什么? 我省略了它并运行了命令,它运行正常.

What exactly is the purpose of the 2> part of the command? I omitted it and ran the command, it just works fine.

并且,如果ls的输出存储在/dev/null文件中,则变量scriptlist确切包含什么. 当我执行代码时,输​​出在变量中,文件null中没有任何内容.如果删除2,则输出在文件中,而不是变量中. 知道这行代码到底在做什么吗?

And, if the output of ls is getting stored in /dev/null file, what exactly the variable scriptlist will contain. When I executed the code, the output was in the variable and nothing was there in file null. If we remove 2, then output is in file instead of variable. Any idea what exactly this line of code doing?

推荐答案

文件描述符2表示标准错误. (其他特殊文件描述符包括用于标准输入的0和用于标准输出的1).

File descriptor 2 represents standard error. (other special file descriptors include 0 for standard input and 1 for standard output).

2> /dev/null表示将标准错误重定向到/dev/null. /dev/null是一种特殊的设备,它将丢弃所有写入其中的内容.

2> /dev/null means to redirect standard error to /dev/null. /dev/null is a special device that discards everything that is written to it.

将这些代码放在一起,将命令ls $directory_/fallback_* 2> /dev/null的标准输出存储到变量scriptlist中,并丢弃标准错误.

Putting all together, this line of code stores the standard output of command ls $directory_/fallback_* 2> /dev/null into the variable scriptlist, and the standard error is discarded.

这篇关于2>是什么?在Unix命令行上是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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