当我使用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由于这些输出,我无法调试命令。
为什么set -x要调试我的.zshrc?我希望set -x只调试后面跟着set -x的行。
发布于 2020-07-05 15:12:09
如果试图调试脚本,则不要在终端上使用set -x (即调试终端中运行的外壳)。相反,您可以使用解释器的-x选项启动脚本(例如,zsh -x [])。
例如,如果您有一个名为ex.zsh的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!发布于 2023-02-01 01:54:33
在shell中运行set -x会将“一切”置于调试模式中。但是,如果您只想调试一个shell函数,以及它调用的任何东西,您可以使用typeset -ft some_func来标记该函数,以便进行调试。例如:
$ which some_func
some_func() {
echo "hiii"
ls -ls
some_other_func
}
$ typeset -ft some_func
$ some_func
....
...这将使调试输出范围仅限于您所关心的代码。只需运行typeset -f +t some_func就可以关闭调试。如果您想调试一个独立于您的环境的独立脚本,那么就像前面提到的那样,用zsh -x script.sh运行它。
https://unix.stackexchange.com/questions/596715
复制相似问题