小编NZD*_*NZD的帖子

Bash中'2> >(command)'重定向的含义

不久前我制作了一个脚本,并在它周围添加了一些日志记录,但我忘记了日志记录的重定向是如何工作的:-(

它的要点是:

#!/bin/bash

LOGFILE=/some/path/mylogfile

(
  # here go my commands which produce some stdout
  # and, if something goes wrong, also some stderr
) 1>>${LOGFILE} 2> >( tee -a ${LOGFILE} >&2 )
Run Code Online (Sandbox Code Playgroud)

当我运行脚本时,它不会向 打印任何内容stdout,而只会打印到stderr. 日志文件同时${LOGFILE}捕获标准输出和标准错误。

当我运行脚本并且我的终端上没有输出时,我知道一切都很好。如果有任何输出,我知道出了什么问题,我可以检查日志文件以找出问题所在。

现在让我困惑的重定向部分是以下语法: 2> >( some command )

谁能解释一下那里发生了什么?

bash io-redirection shell-script

23
推荐指数
1
解决办法
5992
查看次数

标签 统计

bash ×1

io-redirection ×1

shell-script ×1