I'm trying to send all output to a log, with stderr also displaying in the console.
..with the log entries in order and some method to send comments to the log+console (same as stderr).
exec &> log
For instance, this doesn't work:
#!/bin/bash
exec 2> >(tee log) 2>&1 > build.log
echo "Yes 1"
ugh "No 1"
echo "Yes 2"
ugh "No 2"
echo "Message to user" 3>&1
The examples I'm finding here and elsewhere either put them out of order or redirect both to log and console.
None of the examples send all output to the log - with stderr and 'special messages' also displayed on screen...
Solution
Chris solved this in his answer below. This is the adapted solution:
#!/bin/bash
exec 3> >(tee -a log)
exec 4>>log
exec >&4 2>&3
# Out: To log.
echo "I'm standard output."
# Error: To log and console.
ugh "command not found"
# Message: To log and console.
echo "Message to user." >&3
This writes the to the log / console as the given comment suggests.