Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide commands from xtrace

Tags:

linux

bash

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.

like image 1000
jcalfee314 Avatar asked Dec 11 '25 09:12

jcalfee314


1 Answers

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.

like image 56
that other guy Avatar answered Dec 14 '25 01:12

that other guy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!