I'm trying to learn the effect of exec > >(tee logfile) in the following code:
#!/bin/bash
exec 7>&1 # save stdout for later reset
exec > >(tee logfile) # point stdout to FIFO pointing to tee command?
#+expect any subsequent output to stdout to be sent
#+both to stdout and logfile.
# so let's send some output
echo
echo howdy # expect these strings to be sent both to terminal and
echo g\'day #+logfile
echo hello!
# restore stdout
exec 1>&7
exec 7>&-
#check content of logfile!
echo ------------
cat logfile
I'm just guessing here that exec > >(tee logfile) will redirect stdout to >(tee logfile).
Here's the output to terminal when this script is run:
--------------------
howdy
g'day
hello!
howdy
g'day
hello!
And here's the content of logfile:
howdy
g'day
hello!
It seems my attempt to redirect stdout back to terminal has no effect: exec 1>&7. Perhaps, exec 1>&7 happens AFTER logfile has been written and its content sent to terminal.
And I don't understand the output to terminal when the script is executed. I'm guessing exec > >(tee logfile) is blocked until cat logfile reads it. Then content of logfile is duplicated to terminal due to tee logfile.
Could you help me understand these points?
Thanks.
echo ---that, for our purposes, show the same thing: That the stdout is dumped to the terminal.