开发者

Cryptic Bash command ... purports to log the whole script's execution

开发者 https://www.devze.com 2023-03-21 06:34 出处:网络
I have some code handed from someone long gone to another department. It purports to log everything to the $MBL location, however, it does not; it creates an empty file in the $MBL location :-(

I have some code handed from someone long gone to another department. It purports to log everything to the $MBL location, however, it does not; it creates an empty file in the $MBL location :-(

exec > >(tee ${MBL}) 2>&1

I can tell 开发者_如何转开发that it takes stderr and sends it to stdout; I can tell that tee should output the result to stdout and to $MBL. However, I don't understand the exec > >() syntax.

Reading the bash(1) man page suggests that a fork happens....


Two things going on here: exec with only redirections redirects the shell's own file descriptors, and the >(command) syntax in bash and zsh creates a pipe and substitutes a /dev/fd/* reference to its input.

As written, this looks like it does what it is claimed to do.. but there may be other redirections in the script, or if it's being run in a shell that doesn't support >(command) then it will spit out an error and do nothing useful.

0

精彩评论

暂无评论...
验证码 换一张
取 消