For a bash script project, I write human-readable log info to stdout/stderr. Additionally, I want to write formatted metrics to a third stream that will be discarded by default but can be redirected for piped processing. Is the approach doing this with an additional file descriptor advised?
exec 3> /dev/null
echo "This is stdout"
echo "This is stderr" >&2
echo "This is fd3" >&3
I'm fine with the third line not showing up under normal conditions. However, when used in a certain toolchain I want to pipe these messages. Simple example:
$ bash example.sh 3>&1
This is stdout
This is stderr
The third line does not appear as the console output.
What am I doing wrong? Is there a solution to this? Is another approach advised?