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