I've pulled hair trying to get the redirection right for this but just
come up with the right combination. I'd imagine it involves stashing
away fd 2, duplicating fd 2 to a new fd and then restoring fd back from
where it was stashed, or somesuch.
So to be clear, I want stdout on fd 1, stderr on fd 2 (as they are
normally) and then the xtrace output on some other fd, presumably 3.
Ideas?
b.
Nothing good. The next version of bash will allow you specify an arbitrary
file descriptor where the xtrace output will be written.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU ch...@case.edu http://cnswww.cns.cwru.edu/~chet/
Pity.
> The next version of bash will allow you specify an arbitrary
> file descriptor where the xtrace output will be written.
Cool. I wonder how long it will take the distros to pick that up
though. Sure, I could build my own packages, but the distro/arch matrix
here makes that somewhat prohibitive.
I suppose by that same token trying to play with FDs so that:
foo() {
echo "this is a message the user should see on stdout"
echo "this is the function return value"
}
bar=$(foo)
echo "bar==$bar"
Yields:
$ foo.sh 2>/dev/null
this is a message the user should see on stdout
bar==this is the function return value
Is equally difficult? Or can I more easily play with FD duplication and
redirection to achieve that, even if it means adding a ">&word" at the
end of things I want on the real stdout?
b.
Do you mean "equally difficult" as in "impossible"? Then I would say no,
it looks easier :-)
> Or can I more easily play with FD duplication and redirection to
> achieve that, even if it means adding a ">&word" at the end of things
> I want on the real stdout?
I guess the answer is yes. You cannot redirect the output of "set -x",
but you can redirect your own outputs.
# Duplicate a descriptor to stdout to escape redirections, like for
# instance in command substitution.
exec 3>&1; PRESERVED_STDOUT=3
foo()
{
{
echo "this is a message the user should see on stdout"
} >&${PRESERVED_STDOUT}