#!/bin/bash # inpath--Verifies that a specified program is either valid as is # or can be found in the PATH directory list. proc in_path { # Given a command and the PATH, try to find the command. Returns # 0 if found and executable, 1 if not. Note that this temporarily # modifies the IFS (internal field separator) but restores it # upon completion. setglobal cmd = $1, ourpath = $2, result = '1' setglobal oldIFS = $IFS, IFS = '":'" for directory in [$ourpath] { if test -x $directory/$cmd { setglobal result = '0' # if we're here, we found $cmd in $directory } } setglobal IFS = $oldIFS return $result } proc checkForCmdInPath { setglobal var = $1 if test $var != "" { if test $(var:0:1) = "/" { if test ! -x $var { return 1 } } elif ! in_path $var $PATH { return 2 } } } #if [ $# -ne 1 ] ; then # echo "Usage: $0 command" >&2 ; exit 1 #fi #checkForCmdInPath "$1" #case $? in # 0 ) echo "$1 found in PATH" ;; # 1 ) echo "$1 not found or not executable" ;; # 2 ) echo "$1 not found in PATH" ;; #esac #exit 0