Ana*_*bus 32 bash directory cd-command shell-builtin pwd
例如:
$ ls -aF
./ ../ bin/
$ cd tin # with a tee, not bee
bin
$ pwd
/home/user/bin
Run Code Online (Sandbox Code Playgroud)
换句话说,cd猜测我真正的意思是cd bin,并成功(嗯?)相应地更改当前目录。我没有在Bash 参考手册man bash中找到这种行为的记录。
我希望 Bash 产生一个错误,向标准错误写入一些信息,如果没有找到与参数匹配的目录(考虑扩展) ,则保持当前目录不变。dir
供参考,
$ type cd
cd is a shell builtin
$ ps -p $$
PID TTY TIME CMD
46959 pts/8 00:00:00 bash
$ bash --version
GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2011 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.
$ hostnamectl
Static hostname:
Icon name: computer-server
Chassis: server
Machine ID:
Boot ID:
Operating System: Red Hat Enterprise Linux
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.9:GA:server
Kernel: Linux 3.10.0-1160.83.1.el7.x86_64
Architecture: x86-64
$ #DELETED: Static hostname, Machine ID, Boot ID
Run Code Online (Sandbox Code Playgroud)
Ana*_*bus 45
命令的行为cd受 影响shopt。请参阅man bash,搜索:shopt。另请参阅Bash 参考手册中的内置 Shopt。
特别是,问题中所示的行为与 一致shopt -s cdspell。
我想清除所有影响的选项cd将会达到预期的(根据问题)效果。请参阅Bourne Shell 内置命令cd中或 中的“SHELL BUILTIN COMMANDS”下的描述。man bash
感谢一位未透露姓名的同事指出了我们系统的shopt设置cdspell,这也在之前的评论中得到了承认。