Reputation: 4830
Is there a way to hide a command from the output with xtrace on (set -o xtrace
)?
In DOS, the technique is to turn echo on
but prefix the hidden commands with the @
symbol.
Upvotes: 3
Views: 894
Reputation: 4935
You could do something like this
# At start of script, or where xtrace may be enabled:
[[ "$SHELLOPTS" =~ xtrace ]] && xtrace_on=1
# Later
set +o xtrace
# Your untraced code here
[[ "$xtrace_on" ]] && set -o xtrace
Upvotes: 0
Reputation: 123490
I've never seen a similar trick in bash, but you can sometimes use subshells to temporarily enable tracing for commands you're interested in:
echo "This command is not traced"
(
set -x
echo "This command is traced"
)
echo "No longer traced"
If subshells are not suitable because you want to modify the environment, you can set -x
and then set +x
, but that leaves you with the artifacts of tracing set +x
commands.
Upvotes: 5