hakunin hakunin - 4 months ago 8
Bash Question

Tracing shell commands executed within shell scripts (e.g. zsh)

Given a shell script (with conditions, concatenations and interpolations) that builds and executes certain commands (in my case calls to ImageMagick's

convert
cli), is there a way to list the commands that were executed in that script? Since the script calls
convert
multiple times substituting args, I'd like to get a list like the following.

convert ...
convert ...
convert ...
...


I'm using zsh in OS X, but can switch to bash, etc.

Answer

Stick a

set -x

at the top of your script. Works in bash, should work in zsh.