bash 这个shell命令是什么意思“exec 3>&1 > >(logger -t "OKOK")”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12194616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does this shell command mean "exec 3>&1 > >(logger -t "OKOK")"
提问by Kit Ho
I've found the following bash command in some source code.
我在一些源代码中发现了以下 bash 命令。
exec 3>&1 > >(logger -t "OKOK")
What does it exactly mean?
它到底是什么意思?
As far as I know, it redirects those log to the syslog.
据我所知,它将这些日志重定向到系统日志。
However, What is 3>&1?
然而,什么是3>&1?
I have never seen a file descriptor of 3 before.
我以前从未见过文件描述符为 3。
回答by fduff
unusual indeed, but it does exist:
确实不寻常,但确实存在:
Each open file gets assigned a file descriptor. The file descriptors for stdin, stdout, and stderr are 0, 1, and 2, respectively. For opening additional files, there remain descriptors 3 to 9. It is sometimes useful to assign one of these additional file descriptors to stdin, stdout, or stderr as a temporary duplicate link. This simplifies restoration to normal after complex redirection and reshuffling
每个打开的文件都会分配一个文件描述符。stdin、stdout 和 stderr 的文件描述符分别为 0、1 和 2。为了打开额外的文件,还有描述符 3 到 9。有时将这些附加文件描述符之一分配给 stdin、stdout 或 stderr 作为临时重复链接很有用。这简化了复杂重定向和改组后恢复正常的过程
Find out more on the IO redirection page.
在IO 重定向页面上了解更多信息。
回答by choroba
From this line on, everything printed to STDOUT will be processed by logger. The original STDOUT has been saved in fd3, so you can later (if needed) restore the normal STDOUT. See Advanced BASH Scripting Guidefor details.
从这一行开始,打印到 STDOUT 的所有内容都将由logger. 原始 STDOUT 已保存在 fd3 中,因此您可以稍后(如果需要)恢复正常的 STDOUT。有关详细信息,请参阅高级 BASH 脚本指南。

