Tuesday, April 8, 2014

Bash: print commands as they execute

I'm making a demo script that calls programs from a toolchain I am developing. The idea of the script is that it runs a set of commands in sequence and also prints what the command will be doing. Say the base script was:

python do_this.py

I first put in echo to describe the command

echo 'Now we do blah blah'
python do_this.py


But, I wanted to see the commands too. I discovered the set -x command, which starts the debug mode and prints out every command as it is executed.

set -x
echo 'Now we do blah blah'
python do_this.py


But, this now, effectively, printed out the description twice: once when printing the echo statement and then again when actually executing the echo statement. Then I discovered the No OPeration (NOP) character for bash ":".

set -x
: Now we do blah blah
python do_this.py

This prints the line but does not try to execute it.

No comments:

Post a Comment