diff options
Diffstat (limited to 'inpath')
-rwxr-xr-x | inpath | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -0,0 +1,44 @@ +#!/bin/sh + +in_path () { + local cmd=$1 path=$2 res=1 + local IFS=":" + + for dir in $path; + do + if [ -x "$dir/$cmd" ]; then + res=0 + break + fi + done + + return $res +} + +cmd_in_path () { + var=$1 + + if [ -n "$var" ]; then + if [ $(echo "$var" | cut -c 1) = "/" ]; then + if [ ! -x $var ]; then + return 1 + fi + elif ! in_path $var "$PATH"; then + return 2 + fi + fi +} + +if [ $# -ne 1 ]; then + echo "Usage: $0 <command>" >&2 + exit 1 +fi + +cmd_in_path "$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 |