diff options
author | filip <“filip.rabiega@gmail.com”> | 2025-07-03 21:27:06 +0200 |
---|---|---|
committer | filip <“filip.rabiega@gmail.com”> | 2025-07-03 21:27:06 +0200 |
commit | 1feb678fc3d52a7a3c4e31bb153783852fa08a58 (patch) | |
tree | 9fdd767c7a3324440b96477e64d2cf9b8f62494b /inpath | |
parent | 54a39b322d1e13911d8f03d533ee1ed1a2af17d5 (diff) | |
download | chadscripts-1feb678fc3d52a7a3c4e31bb153783852fa08a58.tar.gz chadscripts-1feb678fc3d52a7a3c4e31bb153783852fa08a58.tar.bz2 chadscripts-1feb678fc3d52a7a3c4e31bb153783852fa08a58.zip |
added new stuff
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 |