I have a large bash script and I want to globally redirect all stdout/stderr to a file, except some progress indicators such specific echo messages. For example, consider the following script
#!/bin/bash
# all stdout and stderr go to out.log
exec &> out.log
special_echo "starting"
# many other commands go here
# which output both the stdout and stderr
# also some special_echo commands in here,
# for example
echo "msg1"
special_echo "middle"
echo "msg2" >&2
special_echo "finished"
When it is run the output should be
$ ./script
starting
middle
finished
$
But, out.log
should contain
msg1
msg2
How to implement special_echo
functionality? I've tried using a file descriptor and echoing to that but can't get it to display on the screen.
Is there a way to achieve this without appending redirection to every line or doing something like in this answer?