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
You are likely running
kshor possibly Bash for your interactive shell. Both of these have a-poption fortype. The shell (probablysh) that your script is running in hastypebut doesn’t have the-poption so it’s looking for “-p” as the name of an executable and it doesn’t find it.So you could change your script to use
kshor you could use thewhichprogram. The latter is probably more portable, since some systems don’t haveksh.