I have the following two bash scripts:
one.bash:
#!/bin/bash
echo "I don't control this line of output to stdout"
echo "I don't control this line of output to stderr" >&2
echo "I do control this line of output to fd 5" >&5
callone.bash:
#!/bin/bash
# here I try to merge stdout and stderr into stderr.
# then direct fd5 into stdout.
bash ./one.bash 1>&2 5>&1
When I run it like this:
bash callone.bash 2>stderr.txt >stdout.txt
The stderr.txt file looks like this:
I don't control this line of output to stdout
I don't control this line of output to stderr
I do control this line of output to fd 5
and stdout is empty.
I would like the "do control" line to be output to only stdout.txt.
The restrictions on making changes are:
- I can change anything in callone.bash.
- I can change the line in one.bash that I control.
- I can add an exec in one.bash related to file descriptor 5.
- I have to run the script as indicated.
[EDIT] The use case for this is: I have a script that does all kinds of running of other scripts that can output to stderr and stdout. But I need to ensure that the user only sees the well controlled message. So I send the well controlled message to fd5, and everything else (stdout & stderr) is sent to the log.