changed $ which to POSIX compliant command -v