In bash, when running with the -x option, is it possible to exempt individual commands from echoing?I'm trying to make the output as neat as possible, so I am running certain parts of my script in a subshell with set +x. However, the row set +x itself is still echoed and adds no valuable information to the output.I remember back in the bad old .bat days, when running with echo on, individual lines could be exempted by starting them with a @. Is there any equivalent in bash?#!/bin/bash -xfunction i_know_what_this_does() {  (    set +x    echo do stuff  )}echo the next-next line still echoes 'set +x', is that avoidable?i_know_what_this_doesecho and we are back and echoing is back onWhen running the above, output is:+ echo the next-next line still echoes 'set +x,' is that 'avoidable?'the next-next line still echoes set +x, is that avoidable?+ i_know_what_this_does+ set +xdo stuff+ echo and we are back and echoing is back onand we are back and echoing is back on
bash: escape individual lines from `-x` echoing
bash;shell;debugging
xtrace output goes to stderr, so you could redirect stderr to /dev/null:ikwtd() {  echo do stuff} 2> /dev/nullIf you still want to see the errors from the commands run inside the functions, you could doikwtd() (  { set +x; } 2> /dev/null # silently disable xtrace  echo do stuff)Note the use of (...) instead of {...} to provide a local scope for that function via a subshell. bash, since version 4.4 now supports local - like in the Almquist shell to make options local to the function (similar to set -o localoptions in zsh), so you could avoid the subshell by doing:ikwtd() {  { local -; set +x; } 2> /dev/null # silently disable xtrace  echo do stuff}An alternative for bash 4.0 to 4.3 would be to use the $BASH_XTRACEFD variable and have  a dedicated file descriptor open on /dev/null for that:exec 9> /dev/nullset -xikwtd() {  { local BASH_XTRACEFD=9; } 2> /dev/null # silently disable xtrace  echo do stuff}Since bash lacks the ability to mark a fd with the close-on-exec flag, that has the side effect of leaking that fd to other commands though.See also this locvar.sh which contains a few functions to implement local scope for variables and functions in POSIX scripts and also provides with trace_fn and untrace_fn functions to make them xtraced or not.