如何在定制后调试Shell命令 [英] How to debug Shell command after customization

查看:159
本文介绍了如何在定制后调试Shell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一些时间自定义我的配置,如许多人做的。基本上,我从一个git存储库里我所有的dotfiles(.zshrc,.vimrc,...)符号链接,然后我改变了很多东西。



我在Mac OS X和我的配置工作得很好。但是当我在Linux(Ubuntu)上使用相同的dotfiles时,我会得到一些差异。



我使用 ZSH prezto



当我做 cd 我收到这个消息

  20:17〜❯cd项目

脚本:无效选项 - 'G'

用法:
脚本[选项] [文件]

选项:
-a,--append附加输出
-c,--command< command>运行命令而不是交互shell
-r, - 返回退出代码的子进程
-f,--flush运行flush每次写入
--force即使使用输出文件它是一个链接
-q, - 安静
-t,--timing [=< file>]将时间数据输出到stderr(或FILE)
-V, --version输出版本信息并退出
-h,--help显示此帮助并退出

类型命令(键入cd )给我

  cd是一个别名为nocorrect cd 
cd是一个shell内置

我在这里发布知道是否任何人都知道一种方法来调试这种错误。错误信息不是很清楚,我不知道要在哪里和在哪里寻找。



任何想法?



我的大多数配置来自于其他许多人的配置。

解决方案

一般来说,你可以开始 zsh 与参数 -x 进行调试。这将返回在执行之前由此shell运行的任何shell代码行。这有助于确定您的配置中哪里出现错误。






在这种情况下,您会收到脚本,因为除了所有可用选项的列表之外,它没有选项'G'(尝试并比较 script -G )。命令行工具通常在不同的Unix衍生工具之间有很大不同,包括命令行选项的数量和含义。在您的平台之间比较 man script



As cd nocorrect cd nocorrect 的别名似乎是最可能的罪魁祸首。要检查,运行 unalias cd 。如果问题消失,请执行类型nocorrect 并从那里进行。



如果问题仍然存在,搜索您的配置对于 chpwd (这可能是一个函数定义或一行,如 add-zsh-hook chpwd SOMETHING )。 / p>

I spent some time on customizing my configuration like many people do. Basically I symlink all my dotfiles (.zshrc, .vimrc,...) from a git repository then I changed a lot of stuff.

I'm on Mac OS X and my configuration works very well. However when I use the same dotfiles on Linux (Ubuntu) I get some differences. Most of them are minor differences but on is VERY annoying.

I use ZSH and prezto

When I do cd I get this message

20:17 ~ ❯ cd Projects                                                                                            

script: invalid option -- 'G'

Usage:
 script [options] [file]

Options:
 -a, --append            append the output
 -c, --command <command> run command rather than interactive shell
 -r, --return            return exit code of the child process
 -f, --flush             run flush after each write
     --force             use output file even when it is a link
 -q, --quiet             be quiet
 -t, --timing[=<file>]   output timing data to stderr (or to FILE)
 -V, --version           output version information and exit
 -h, --help              display this help and exit

The type command (type cd) give me

    cd is an alias for nocorrect cd
    cd is a shell builtin

I am posting here to know if anyone know a way to debug this kind of error. The error message isn't very clear and I don't know what and where to look for.

Any ideas ?

Most of my configuration comes from many other people's configuration.

解决方案

Generally, you can start zsh with the parameter -x for debugging. This will echo any line of shell code run by this shell before it is executed. This helps locating where in your configuration things go awry.


In this case you get an error message from script because it does not have an option 'G' in addition to a lists of all available options (try and compare script -G). Command line tools often differ quite a bit between different Unix derivatives, that includes number and meaning of command line options. Compare man script between your platforms.

As cd is an alias for nocorrect cd, nocorrect seems to be the most likely culprit. To check, run unalias cd. If the problem goes away, do a type nocorrect and go from there.

If the problem persists search your configuration for chpwd (this may be either a function definition or a line like add-zsh-hook chpwd SOMETHING).

这篇关于如何在定制后调试Shell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆