Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: 3.1.6-test-1: strange cd behaviour



Andrej Borsenkow wrote:

> (/tools/src  is in cdpath)
> 
> bor@itsrm2:/tools/src/zsh-3.1.6-test-1%> builtin cd zsh-3.1.6-test-1/..
> bor@itsrm2:/tools/src/zsh-3.1.6-test-1%> echo $?
> 0
> bor@itsrm2:/tools/src/zsh-3.1.6-test-1%> /bin/pwd
> /tools/src/zsh-3.1.6-test-1
> 
> That is, cd does not change directory and returns success. I have some scripts
> that do "cd /some/dir && rm -r ..." ahem ...

That's a bit tricky... you have either no `.' in your `cdpath', or it is 
before /tools/src, right?

The problem is that cd_do_chdir() calls cd_try_chdir() with all
elements from `cdpath' -- if cdpath contains no `.', it first calls
cd_try_chdir() for the current directory (always plus the argument
given to `cd'). Well, cd_try_chdir() builds the full path (directory
from `cdpath' or current directory and the argument) and then calls
fixdir() -- which reduces /foo/bar/baz/.. to /foo/bar. So if `.' is
tested first and you try to `cd' to `dir/..', `cd' will always decide to
go to the current directory -- i.e. do nothing.

So the workaround for now is to put a `.' at the end of `cdpath'.

Hm, should we just document this or change it -- and how?

Bye
 Sven


--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author