Can you explain the mechanism behind the following line in a script?
exec > >(tee logfile.txt)
this basically outputs both STDOUT to the console and also logfile.txt when it’s in a script. I know what it does, but I cannot explain exactly why it works the way it does. I understand >(command args) is a process substitution. My main confusion comes from why having extra “>”?
why not exec >(tee logfile.txt)?
See the help for
exec($ help exec). The relevant part isSince each command inherits its standard output from the shell that spawns it,
every command now has the given process substitution as its standard output, rather
than the terminal.