In a bash script I have a log()
function that is used in several places, as well as a logs()
function that diverts lots of line to log()
. When I run parts of the script with set -x
, obviously all commands within logs()
and log()
are traced too.
I would like to define logs()
and log()
such that at least their content, at best even their call is suppressed from set -x
output.
Best Answer
A quick and dirty hack that should work in all shells is to (temporarily) make your
log
an external script instead of a function.In bash you could also use a
trap '...' DEBUG
andshopt -s extdebug
combination, which is much more versatile thanset -x
. Example:(Of course, you can dispense with the strange format + indenting and make it completely
set-x
-like; you can also redirect it to another file instead of mixed with the stderr from commands.)Then:
will result in: