What exactly does this do: exec > > (command)
I saw here and here too the following construction:
exec > >(tee -a script.log)
开发者_JAVA技巧I know what the tee command is, and the (command...) usually means execute the command
in a subshell, and exec replaces the current shell with a program, like exec ls
, (but here there is no command) and additionally what is meant with the > >
?
Can anybody clarify this dark wizzardy?
exec >{space}> (command)
@Seth? :) Any pointer where i can read more about this magic would be appreciated. :)
It replaces the current bash
session with another, and writes the output of all commands to script.log
.
In that way, you can use your bash
shell normally, and you wouldn't see any difference (mostly), but all output is going to show up on your screen and in the script.log
file.
From exec manpages:
If command is supplied, it replaces the shell without creating a new process. If no command is specified, redirections may be used to affect the current shell environment.
The >(tee -a script.log)
magic creates a pipe, so instead of writing to a file like we would (with >> script.log
in this case), we write to the process tee -a script.log
, which does the same. For some reason unbeknown to me, using >>
does not work, but writing to the named pipe works. Source here
精彩评论