开发者

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

开发者 https://www.devze.com 2023-02-11 01:01 出处:网络
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 command

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.


Stick a

set -x

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


In zsh (maybe only with oh-my-zsh enabled) I find there's a lot of noise produced with set -x or setopt xtrace.

But you can also:

typeset -ft <function_name>

to trace only one function.

To turn it off:

typeset +ft <function_name>

Adapted from the A User's Guide to the Z-Shell.

0

精彩评论

暂无评论...
验证码 换一张
取 消