I like to use
set -x in scripts to show what's going on, especially if the script is going to run in a CI/CD pipeline and I might need to debug some failure post-hoc.
One annoyance with doing this is that if I want to echo some text to the user (e.g., a status message or
"I'm starting to do $X") then that message gets output twice - once for the
echo command itself being echoed, and then once as the output of that
What's a good way to make this nicer? One solution is this:
... bunch of normal commands that get echoed
# Temporarily don't echo, so we don't double-echo
echo "Here is my status message"
... rest of commands get echoed again
But the two problems with that are
- That's a lot of machinery to write every time I want to tell the user something, and it's "non-obvious" enough that it probably requires the comment every time
- It echoes the
set +xtoo, which is undesirable.
Is there another option that works well?
Something like Make's feature of prepending an
@ to suppress echoing would be great, but I've not been able to find such a feature in Bash.