我习惯打字
$ cd
无需参数即可在 bash shell 中导航到我的主目录。
然而,由于某个不确定的时间,它不再起作用,根本就没有任何作用。
我的HOME
变量已设置:
$ echo $HOME
/home/me
这怎么可能?手册页上说
If no directory operand is given and the HOME environment variable is set to a non-empty
value, the cd utility shall behave as if the directory named in the HOME environment
variable was specified as the directory operand.
一些相关内容:
$ uname -a
Linux eris 4.15.0-96-generic #97-Ubuntu SMP Wed Apr 1 03:25:46 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
答案1
我猜你的 .alias 或 .bashrc 文件有问题。你可以尝试删除所有与 cd 相关的别名。使用以下命令查看是否有问题:
cat $HOME/.alias | grep 'cd '
或者
cat $HOME/.bashrc | grep 'cd '
如果确实有问题,则用 nano 打开它并删除/修复这个错误的行。
nano $HOME/.alias
source $HOME/.alias
或者
nano $HOME/.bashrc
source $HOME/.bashrc