Check if a program exists in bash

Posted by ~rojanu on Stack Overflow See other posts from Stack Overflow or by ~rojanu
Published on 2010-04-09T15:30:30Z Indexed on 2010/04/09 15:33 UTC
Read the original article Hit count: 266

Filed under:
|
|

I am trying to check if md5sum or digest exists on solaris and script is used on different machines.

Here is the function in sh script which is called from a ksh script

getMD5cmd ()
{
    PATH="${PATH}:/bin:/usr/bin:/usr/sfw/bin:/usr/local/bin:/usr/sbin/bin"
    if type -p md5sum;then
        MD5CMD=`type -p md5sum`
    elif type -p digest;then
        MD5CMD="`type -p digest` -a md5"
    fi
    echo "HERE ${MD5CMD}"
}

When I run scripts I get

-p not found
md5sum not found
-p not found
digest is /bin/digest
HERE

However, when I type it in a terminal, works as exptected

Any Ideas? Thanks

© Stack Overflow or respective owner

Related posts about bash

Related posts about solaris