I like using the -x switch with bash to debug scripts. The only downside is that the echo commands are also display which may create a lot of unnecessary duplicates:
#!/bin/bash
echo "Changing to /etc directory"
cd /etc
Then once run:
$ bash -x test.sh
+ echo 'Changing to /etc directory'
Changing to /etc directory
+ cd /etc
I tried filtering out with bash -x test.sh | grep -v '+ echo' but it doesn’t work.
[Q] Is there a way I can prevent -x to also display echo commands?
Thanks
You could filter it through a regex engine of your choice:
or