sh: Correct criterion for using CDPATH in cd.
CDPATH should be ignored not only for pathnames starting with '/' but also for pathnames whose first component is '.' or '..'. The man page already describes this behaviour.
This commit is contained in:
parent
7e2548ae0a
commit
64fa41f3e1
@ -123,7 +123,10 @@ cdcmd(int argc, char **argv)
|
||||
else
|
||||
dest = ".";
|
||||
}
|
||||
if (*dest == '/' || (path = bltinlookup("CDPATH", 1)) == NULL)
|
||||
if (dest[0] == '/' ||
|
||||
(dest[0] == '.' && (dest[1] == '/' || dest[1] == '\0')) ||
|
||||
(dest[0] == '.' && dest[1] == '.' && (dest[2] == '/' || dest[2] == '\0')) ||
|
||||
(path = bltinlookup("CDPATH", 1)) == NULL)
|
||||
path = nullstr;
|
||||
while ((p = padvance(&path, dest)) != NULL) {
|
||||
if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {
|
||||
|
10
tools/regression/bin/sh/builtins/cd6.0
Normal file
10
tools/regression/bin/sh/builtins/cd6.0
Normal file
@ -0,0 +1,10 @@
|
||||
# $FreeBSD$
|
||||
|
||||
set -e
|
||||
cd -P /bin
|
||||
d=$PWD
|
||||
CDPATH=/:
|
||||
cd -P .
|
||||
[ "$d" = "$PWD" ]
|
||||
cd -P ./
|
||||
[ "$d" = "$PWD" ]
|
15
tools/regression/bin/sh/builtins/cd7.0
Normal file
15
tools/regression/bin/sh/builtins/cd7.0
Normal file
@ -0,0 +1,15 @@
|
||||
# $FreeBSD$
|
||||
|
||||
set -e
|
||||
cd /usr/bin
|
||||
[ "$PWD" = /usr/bin ]
|
||||
CDPATH=/:
|
||||
cd .
|
||||
[ "$PWD" = /usr/bin ]
|
||||
cd ./
|
||||
[ "$PWD" = /usr/bin ]
|
||||
cd ..
|
||||
[ "$PWD" = /usr ]
|
||||
cd /usr/bin
|
||||
cd ../
|
||||
[ "$PWD" = /usr ]
|
Loading…
Reference in New Issue
Block a user