sh: Forget all cached command locations on any PATH change.
POSIX requires this and it is simpler than the previous code that remembered command locations when appending directories to PATH. In particular, PATH=$PATH is no longer a no-op but discards all cached command locations.
This commit is contained in:
parent
604e8224f8
commit
ef0cb80dd4
@ -494,30 +494,7 @@ hashcd(void)
|
||||
void
|
||||
changepath(const char *newval)
|
||||
{
|
||||
const char *old, *new;
|
||||
int idx;
|
||||
int firstchange;
|
||||
|
||||
old = pathval();
|
||||
new = newval;
|
||||
firstchange = 9999; /* assume no change */
|
||||
idx = 0;
|
||||
for (;;) {
|
||||
if (*old != *new) {
|
||||
firstchange = idx;
|
||||
if ((*old == '\0' && *new == ':')
|
||||
|| (*old == ':' && *new == '\0'))
|
||||
firstchange++;
|
||||
old = new; /* ignore subsequent differences */
|
||||
}
|
||||
if (*new == '\0')
|
||||
break;
|
||||
if (*new == ':') {
|
||||
idx++;
|
||||
}
|
||||
new++, old++;
|
||||
}
|
||||
clearcmdentry(firstchange);
|
||||
clearcmdentry(0);
|
||||
}
|
||||
|
||||
|
||||
|
12
tools/regression/bin/sh/execution/hash1.0
Normal file
12
tools/regression/bin/sh/execution/hash1.0
Normal file
@ -0,0 +1,12 @@
|
||||
# $FreeBSD$
|
||||
|
||||
T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit
|
||||
trap 'rm -rf "${T}"' 0
|
||||
PATH=$T:$PATH
|
||||
ls -ld . >/dev/null
|
||||
cat <<EOF >"$T/ls"
|
||||
:
|
||||
EOF
|
||||
chmod 755 "$T/ls"
|
||||
PATH=$PATH
|
||||
ls -ld .
|
Loading…
x
Reference in New Issue
Block a user