On 2023/03/10 13:31, Theo Buehler wrote:
> > Other shells do not have this bug, such as bash, yash, mksh, ash, dash.

mksh does behave the same way as OpenBSD's ksh. I tested a source
build and the Debian package.

> On the other hand, ksh93 behaves the same way as ksh.
> 
> Obviously zsh has a configuration knob for this, conspicuously named
> CD_POSIX:
> 
> https://zsh.sourceforge.io/Doc/Release/Options.html
> 
> Indeed, see point 5:
> 
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cd.html

It changed in the spec.

SUSv2 (1998) suggests to me that cd should not change to a directory
under the current directory unless CDPATH includes . or an empty
component.
https://pubs.opengroup.org/onlinepubs/007908799/xcu/cd.html

2004 has https://pubs.opengroup.org/onlinepubs/009604599/utilities/cd.html
which adds the set of steps and is much closer to the current one.
Point 5 is "check all the CDPATH dirs, if the dir given to the cd
command exists then skip to #7, otherwise fall through to #6", and
#6 is "use the dir given to the cd command directly", i.e. the bash
type behaviour rather than ksh type behaviour.

If you want consistent behaviour between shells you must specify .
(or an empty directory) anyway; bash follows the posix spec:

bash-5.2$ cd
bash-5.2$ ls -d bin
bin
bash-5.2$ CDPATH=/usr cd bin
/usr/bin
bash-5.2$ cd
bash-5.2$ CDPATH=.:/usr cd bin
bash-5.2$ pwd
/home/sthen/bin

But zsh default setting does not:

bamboo% CDPATH=/usr cd bin
bamboo% pwd
/home/sthen/bin
bamboo% cd
bamboo% CDPATH=.:/usr cd bin
bamboo% pwd
/home/sthen/bin

("setopt POSIX_CD" and it does behave like bash).

All a bit of a mess isn't it. ksh's behaviour does at least mean
you're less likely to change to an unexpected directory.

> > but i beg to differ and say this should be fixed i suppose.
> 
> While I have no opinion on whether this behavior makes sense, can or
> should be changed, I'm quite confident that this is not a bug.

+1

Reply via email to