#!/usr/bin/env bash
exec {BASH_XTRACEFD}>./xtrace.log
declare -p BASH_XTRACEFD
set -x
{ : "how do you hide this in ./xtrace.log?"; } 2>/dev/null # fail
# { :; } "${BASH_XTRACEFD:-2}">/dev/null # syntax error
$ ./above_script.bash
declare -- BASH_XTRACEFD="10"
$ cat ./xtrace.log
+ : 'how do you hide this in ./xtrace.log?'
After a block, a literal, hardcoded file descriptor number works, but you cannot use a variable value.
{ : something; } 2>/dev/null works, it outputs nothing in xtrace, when BASH_XTRACEFD is unset, but:
{ : "How do you hide this from xtrace?"; } "${BASH_XTRACEFD:-2}">/dev/null produces a syntax error.
Is there any way, to silence the call, when BASH_XTRACEFD is set?
2> /dev/nulldiscards all errors in addition of the xtrace output, which kind of defeats the purpose of using$BASH_XTRACEFDin the first place which is about having the traces separate from errors.