Por que o CDPATH não funciona conforme documentado nos manuais?

4

O manual do shell Bourne Again diz, de cd dir :

[…] each directory name in CDPATH is searched for dir. […] If dir begins with a slash (/), then CDPATH is not used.

O manual do shell Z diz, de cd arg :

Otherwise, if arg begins with a slash, attempt to change to the directory given by arg.

If arg does not begin with a slash, the behaviour depends on whether the current directory . occurs in the list of directories contained in the shell parameter cdpath. […] If . occurs in cdpath, then cdpath is searched strictly in order so that . is only tried at the appropriate point.

O manual do shell POSIX Ordinary diz, de CDPATH :

Works the same way as PATH for those directories not beginning with / in cd commands.

O manual do shell do Debian Almquist diz, de cd :

If […] the shell variable CDPATH is set and the directory name does not begin with a slash, then the directories listed in CDPATH will be searched for the specified directory.

O manual da shell '93 Korn diz, de cd arg :

If arg begins with a / then the search path is not used. Otherwise, each directory in the path is searched for arg.

O manual da shell MirBSD Korn diz, de CDPATH :

It works the same way as PATH for those directories not beginning with / in cd commands.

Com a única exceção do shell '93 Korn, nenhum desses é realmente o caso:

% export CDPATH=/tmp:
% mkdir wibble /tmp/wibble
% ksh93 -c 'cd ./wibble'
/tmp/wibble
% dash -c 'cd ./wibble ; pwd'
/home/JdeBP/wibble
% bash -c 'cd ./wibble ; pwd'
/home/JdeBP/wibble
% mksh -c 'cd ./wibble ; pwd'
/home/JdeBP/wibble
% lksh -c 'cd ./wibble ; pwd'
/home/JdeBP/wibble
% posh -c 'cd ./wibble ; pwd'
/home/JdeBP/wibble
% zsh -c 'cd ./wibble ; pwd'
/home/JdeBP/wibble
% 

/tmp/./wibble existe e é um diretório, mas apenas o shell '93 Korn está pesquisando CDPATH e localizando-o. O resto não é.

Por que não?

    
por JdeBP 18.01.2018 / 14:55

1 resposta

4

Porque os manuais estão errados .

A shell '93 Korn também está errada.

A única Especificação Unix de 1997 diz:

If the directory operand does not begin with a slash (/) character, and the first component is not dot or dot-dot, cd will search for directory relative to each directory named in the CDPATH variable, in the order listed.

A Especificação Unix Única de 2016 diz o mesmo de uma maneira diferente e um pouco redundante:

3. If the directory operand begins with a <slash> character, set curpath to the operand and proceed to step 7.

4. If the first component of the directory operand is dot or dot-dot, proceed to step 6.

[…]

6. Set curpath to the directory operand.

Nenhum dos manuais menciona a parte sobre . e .. , mas isso é o que toda casca além da shell '93 Korn está realmente fazendo, apesar do que seus manuais dizem:

% export CDPATH=/tmp:
% lksh -c 'cd wibble'
/tmp/wibble
% dash -c 'cd wibble'
/tmp/wibble
% posh -c 'cd wibble'
/tmp/wibble
% bash -c 'cd wibble'
/tmp/wibble
% mksh -c 'cd wibble'
/tmp/wibble
% zsh -c 'cd wibble ; pwd'
/tmp/wibble
% 
    
por 18.01.2018 / 14:55