我刚刚发现当我输入
时,我的OSX bash表现得像这样$ cd code/hack/foo/
$ ls # empty directory
$ cd 0
$ pwd
/Users/hrvoje
$ cd -
$ pwd
/code/hack/foo
$ cd 123
$ pwd
/Users/hrvoje
我的问题是 - 为什么cd 0
或cd 123
将目录更改为$HOME
而不是显示有关丢失目录的错误?
编辑:运行set -x
并更改cd 123
之后,这是PS4
的输出。
::::+[[ exec_scmb_expand_args builtin cd 0 != '' ]]
::::+chruby_auto
::auto.sh:chruby_auto:44+local dir=/Users/hrvoje/code/hack/foo/ version
::auto.sh:chruby_auto:44+[[ -z /Users/hrvoje/code/hack/foo/ ]]
::auto.sh:chruby_auto:44+dir=/Users/hrvoje/code/hack/foo
::auto.sh:chruby_auto:44+[[ -n '' ]]
::auto.sh:chruby_auto:44+[[ -z /Users/hrvoje/code/hack/foo ]]
::auto.sh:chruby_auto:44+dir=/Users/hrvoje/code/hack
::auto.sh:chruby_auto:44+[[ -n '' ]]
::auto.sh:chruby_auto:44+[[ -z /Users/hrvoje/code/hack ]]
::auto.sh:chruby_auto:44+dir=/Users/hrvoje/code
::auto.sh:chruby_auto:44+[[ -n '' ]]
::auto.sh:chruby_auto:44+[[ -z /Users/hrvoje/code ]]
::auto.sh:chruby_auto:44+dir=/Users/hrvoje
::auto.sh:chruby_auto:44+[[ -n '' ]]
::auto.sh:chruby_auto:44+[[ -z /Users/hrvoje ]]
::auto.sh:chruby_auto:44+dir=/Users
::auto.sh:chruby_auto:44+[[ -n '' ]]
::auto.sh:chruby_auto:44+[[ -z /Users ]]
::auto.sh:chruby_auto:44+dir=
::auto.sh:chruby_auto:44+[[ -n '' ]]
::auto.sh:chruby_auto:44+[[ -z '' ]]
::auto.sh:chruby_auto:44+[[ -n '' ]]
:::+exec_scmb_expand_args builtin cd 0
::status_shortcuts.sh:exec_scmb_expand_args:44+scmb_expand_args builtin cd 0
::status_shortcuts.sh:scmb_expand_args:0+'[' builtin = --relative ']'
::status_shortcuts.sh:exec_scmb_expand_args:44+sed -e 's/\([][|;()<>^ "'\''&]\)/\\\1/g'
::status_shortcuts.sh:scmb_expand_args:0+first=1
::status_shortcuts.sh:scmb_expand_args:0+OLDIFS='
'
::status_shortcuts.sh:scmb_expand_args:0+IFS=' '
::status_shortcuts.sh:scmb_expand_args:0+for arg in "$@"
::status_shortcuts.sh:scmb_expand_args:0+[[ builtin =~ ^[0-9]{0,4}$ ]]
::status_shortcuts.sh:scmb_expand_args:0+[[ builtin =~ ^[0-9]+-[0-9]+$ ]]
::status_shortcuts.sh:scmb_expand_args:0+'[' 1 -eq 1 ']'
::status_shortcuts.sh:scmb_expand_args:0+first=0
::status_shortcuts.sh:scmb_expand_args:0+printf %s builtin
::status_shortcuts.sh:scmb_expand_args:0+for arg in "$@"
::status_shortcuts.sh:scmb_expand_args:0+[[ cd =~ ^[0-9]{0,4}$ ]]
::status_shortcuts.sh:scmb_expand_args:0+[[ cd =~ ^[0-9]+-[0-9]+$ ]]
::status_shortcuts.sh:scmb_expand_args:0+'[' 0 -eq 1 ']'
::status_shortcuts.sh:scmb_expand_args:0+printf '\t'
::status_shortcuts.sh:scmb_expand_args:0+printf %s cd
::status_shortcuts.sh:scmb_expand_args:0+for arg in "$@"
::status_shortcuts.sh:scmb_expand_args:0+[[ 0 =~ ^[0-9]{0,4}$ ]]
::status_shortcuts.sh:scmb_expand_args:0+'[' 0 -eq 1 ']'
::status_shortcuts.sh:scmb_expand_args:0+printf '\t'
::status_shortcuts.sh:scmb_expand_args:0+'[' -e 0 ']'
::status_shortcuts.sh:scmb_expand_args:0+_print_path '' e0
::status_shortcuts.sh:_print_path:16+'[' '' = 1 ']'
::status_shortcuts.sh:_print_path:16+eval printf %s '"$e0"'
:::status_shortcuts.sh:_print_path:16+printf %s ''
::status_shortcuts.sh:scmb_expand_args:0+IFS='
'
:status_shortcuts.sh:exec_scmb_expand_args:44+eval 'builtin cd '
::status_shortcuts.sh:exec_scmb_expand_args:44+builtin cd
::::+is_on_git
::.sexy_prompt:is_on_git:1+git rev-parse
::::+parse_git_branch
::repo_index.sh:parse_git_branch:1+/usr/local/bin/git branch --no-color
::repo_index.sh:parse_git_branch:1+sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
答案 0 :(得分:4)
您已经安装了一个名为scm_breeze
的工具,可以自定义shell的行为方式。
此工具支持“编号快捷方式”,并试图扩展您的价值;相关代码为here。
由于没有定义快捷方式0
(也就是说,没有名为e0
的变量),结果是一个空值 - 而cd
没有参数更改为主目录。