I saw here and here too the following construction:
exec > >(tee -a script.log)
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
bashsession with another, and writes the output of all commands toscript.log.In that way, you can use your
bashshell normally, and you wouldn’t see any difference (mostly), but all output is going to show up on your screen and in thescript.logfile.From exec manpages:
The
>(tee -a script.log)magic creates a pipe, so instead of writing to a file like we would (with>> script.login this case), we write to the processtee -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