2 in 2>的含义是什么?/dev/空 [英] What is the meaning of 2 in 2> /dev/null
问题描述
在下面的bash脚本中,我不明白2的含义:
In this following bash script I don't understand what the 2 means:
function kill_process()
{
kill -9 $(lsof -i:$1 -t) 2> /dev/null
}
我可以看到它会将输出重定向到空设备,但是2表示什么?
I can see that the it is redirecting the output to the null device but what does the 2 mean?
推荐答案
Bash中的N>
语法意味着将文件描述符重定向到其他地方. 2
是stderr
的文件描述符,本示例将其重定向到/dev/null
.
The N>
syntax in Bash means to redirect a file descriptor to somewhere else. 2
is the file descriptor of stderr
, and this example redirects it to /dev/null
.
这简单来说意味着什么:忽略命令的错误输出.例如,如果kill
由于该进程不存在而无法停止进程,或者由于当前用户无权停止该进程,则它将在stderr
上打印消息.通过将stderr
重定向到/dev/null
,您可以有效地禁止显示这些消息.
What this means in simple terms: ignore error output from the command. For example, if kill
cannot stop a process because it doesn't exist, or because the current user doesn't have the permission to do that, it would print messages on stderr
. By redirecting stderr
to /dev/null
, you effectively suppress these messages.
这篇关于2 in 2>的含义是什么?/dev/空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!