![exec 1> >(logger -s -t tagname) 2>&1 中 1> 的用途是什么?](https://linux22.com/image/145320/exec%201%3E%20%3E(logger%20-s%20-t%20tagname)%202%3E%261%20%E4%B8%AD%201%3E%20%E7%9A%84%E7%94%A8%E9%80%94%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F.png)
我只是偶然发现
exec 1> >(logger -s -t $(basename $0)) 2>&1
它用于将当前脚本的输出重定向到系统记录器(如果您从未见过这个,但有兴趣查看)https://stackoverflow.com/questions/8888251/understanding-bash-exec-12-command拓宽您的 shell 知识)。
我想知道为什么这1>
是必要的。这似乎是必要的,因为exec >(logger -s -t test) 2>&1
失败的原因是
bash: /dev/fd/63: Permission denied
bash: exec: /dev/fd/63: cannot execute: Permission denied
然而,省略1>
是我凭直觉所做的,因为exec >[some redirection target]
根据上面链接的问题已经足以进行重定向。2>&1
然后像平常一样将 stderr 重定向到 stdout。
我正在使用 bash 4.4.19。
答案1
这是必要的(可以简单地写成extra >
,而不是 the 1
)。这1>
>
>(...)
流程替代将扩展为类似/dev/fd/13
(文件名)的内容,然后>
将标准输出重定向到其中。从那时起> >(...)
。