bash: showing executed commands expect echos
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:
$ 开发者_如何学Cbash -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:
$ ./test.sh 2>&1 | awk '{if(!match($0, /^\+ echo/)){print $0}}'
or
$ ./test.sh 2>&1 | grep -v '^\+ echo'
精彩评论