Strange behaviour of the "cd" command

Ken D'Ambrosio ken at jots.org
Tue Jul 11 15:55:34 UTC 2017


The problem is with ksh -- specifically (I think) ksh's implementation 
of 'cd'.  I fired up ksh, and also created a /.cache directory (and a 
/.foo), and here are some results:

$ cd /.foo  # success
$ cd /.cache # success
$ cd /tmp # success
$ cd ../.foo # failure
ksh: cd: /foo: [No such file or directory]
$ cd ../.cache # failure
ksh: cd: /cache: [No such file or directory]
$ cd ../tmp # success

The thing I find most telling is the error messages, themselves: "/foo: 
No such file or directory".
My *guess* as to what is happening is that it is interpreting the 
leading "." as *the directory* ".", meaning "this directory", meaning, 
in this case, "root", thus the "directory" it's thinking about is 
"/foo", *not* "/.foo".

Congrats.  I could be wrong, but I do believe you've found a bug.

-Ken


On 2017-07-10 08:58, Dr Rainer Woitok wrote:
> Greetings,
> 
> On a rather fresh installation of Kubuntu 16.04 I ran into the 
> following
> problem:
> 
> General information:
> 
> $ uname -a
> Linux tux 4.4.0-81-generic #104-Ubuntu SMP Wed Jun 14 08:17:06 UTC
> 2017 x86_64 x86_64 x86_64 GNU/Linux
> $ echo $SHELL
> /usr/bin/ksh
> $ unset CDPATH
> $ ls -la / | head -4
> total 116
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 .
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 ..
> drwx------   2 root root  4096 2016-05-25 11:19 .cache
> $ cd /.cache
> /usr/bin/ksh: hist[7]: cd: /.cache: [Permission denied]
> 
> The above message is exactly what one would expect, and thus ok.
> 
> $ cd
> $ pwd
> /home/rainer
> $ ls -la ../../ | head -4
> total 116
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 .
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 ..
> drwx------   2 root root  4096 2016-05-25 11:19 .cache
> $ cd ../../.cache
> /usr/bin/ksh: hist[11]: cd: /cache: [No such file or directory]
> $ pwd
> /home/rainer
> 
> However, the error message above  is definitely not what I had 
> expected!
> In the error message mind in particular the missing dot in "/cache".
> 
> What's happening here?
> 
> Sincerely,
>   Rainer




More information about the ubuntu-users mailing list