I’m trying to redirect stdout to /dev/null after duplicating it to fd 3 (in order to throw away a third-party library’s use of stdout). This works just fine in a shell script (including a shell script called from another shell script and a Python script called from a shell script). However, Docker seems to be closing fd 3, so my app can’t write to it.
ubuntu$ cat run.sh
echo No hello from me!
echo Hello from me >&3
ubuntu$ sh run.sh
No hello from me!
run.sh: line 2: 3: Bad file descriptor
ubuntu$ sh run.sh 3>&1 >/dev/null
Hello from me
ubuntu$ docker run --rm -v$PWD:$PWD -w$PWD ubuntu sh run.sh
./run: 2: 3: Bad file descriptor
No hello from me!
ubuntu$ docker run --rm -v$PWD:$PWD -w$PWD ubuntu sh run.sh 3>&1 >/dev/null
./run: 2: 3: Bad file descriptor
ubuntu$
I was expecting the last output to be identical to that of the redirected shell command.