echo: really ensure log messages go to stdout
all echo helpers are used as logging functions with output to go to the terminal. when used in functions that are designed to return a string though the message printed would get incorrectly captured.
the previous fix done in e3a987d9 was stupidly flawed; somehow my testing led me to mistakenly believe that was adequate, but retesting proves that it was not.
here we create a new FD #3 linked to stdout to output the messages on, which testing shows works as I had actually intended it.
e.g. here:
Foo () { if [ "$1" = "a" ]; then printf "foo\n"; else printf "error\n"; fi; }
we get:
~$ Foo a
foo
~$ Foo b
error
~$ XX="$(Foo a)"
~$ echo "${XX}"
foo
~$ XX="$(Foo b)"
~$ echo "${XX}"
error
and as demonstrated, "error" got incorrectly captured by in the variable
whereas here:
exec 3>&1
Foo () { if [ "$1" = "a" ]; then printf "foo\n"; else printf "error\n" >&3; fi; }
it is different in the last case:
~$ XX="$(Foo b)"
error
~$ echo "${XX}"
the error successfully makes it to the terminal, and the variable is an empty string (with a newline automatically printed).
Gbp-Dch: Short