`set -x` 调试我的 `.zshrc`

blu*_*ray 8 command-line debugging zsh shell-script set

当我用来set -x调试命令时,它会输出一些额外的行。

% set -x
+precmd_update_git_vars:1> [ -n '' ']'
+precmd_update_git_vars:1> [ '!' -n '' ']'
+precmd_update_git_vars:2> update_current_git_vars
+update_current_git_vars:1> unset __CURRENT_GIT_STATUS
+update_current_git_vars:3> [[ python == python ]]
+update_current_git_vars:4> _GIT_STATUS=+update_current_git_vars:4> python /home/ismail/zshfiles/gitstatus.py
+update_current_git_vars:4> _GIT_STATUS='' 
+update_current_git_vars:6> __CURRENT_GIT_STATUS=( '' ) 
+update_current_git_vars:7> GIT_BRANCH='' 
+update_current_git_vars:8> GIT_AHEAD='' 
+update_current_git_vars:9> GIT_BEHIND='' 
+update_current_git_vars:10> GIT_STAGED='' 
+update_current_git_vars:11> GIT_CONFLICTS='' 
+update_current_git_vars:12> GIT_CHANGED='' 
+update_current_git_vars:13> GIT_UNTRACKED='' 
+precmd_update_git_vars:3> unset __EXECUTED_GIT_COMMAND
Run Code Online (Sandbox Code Playgroud)

由于这些输出,我无法调试我的命令。

为什么set -x调试我的.zshrc?我set -x只想调试 后面的行set -x

And*_*ton 3

如果您尝试调试脚本,请不要set -x在终端上使用(即调试在终端中运行的 shell)。-x您可以使用解释器选项来启动脚本(例如, zsh -x <scriptname> [<args>])。

例如,如果您有一个名为 的 zsh 脚本ex.zsh,那么您可以执行以下操作:

$ cat /tmp/ex.zsh
#!/bin/zsh

function () {
    echo "Hello, world!"
}
$ zsh -x /tmp/ex.zsh
+/tmp/ex.zsh:3> '(anon)'
+(anon):1> echo 'Hello, world!'
Hello, world!
Run Code Online (Sandbox Code Playgroud)