Jilles Tjoelker ccd0a51fda sh: Write absolute path in command -vV and type
POSIX is pretty clear that command -v, command -V and type shall write
absolute pathnames. Therefore, we need to prepend the current directory's
name to relative pathnames.

This can happen either when PATH contains a relative pathname or when the
operand contains a slash but is not an absolute pathname.
2020-09-01 13:19:15 +00:00

22 lines
556 B
Plaintext

# $FreeBSD$
failures=0
check() {
if [ "$1" != "$2" ] && { [ "$#" -lt 3 ] || [ "$1" != "$3" ]; } then
echo "Mismatch found"
echo "Expected: $2"
if [ "$#" -ge 3 ]; then
echo "Alternative expected: $3"
fi
echo "Actual: $1"
: $((failures += 1))
fi
}
check "$(cd /bin && PATH=. command -v ls)" /bin/ls /bin/./ls
check "$(cd /bin && PATH=:/var/empty/nosuch command -v ls)" /bin/ls /bin/./ls
check "$(cd / && PATH=bin command -v ls)" /bin/ls
check "$(cd / && command -v bin/ls)" /bin/ls
check "$(cd /bin && command -v ./ls)" /bin/ls /bin/./ls