diff options
author | filip <“filip.rabiega@gmail.com”> | 2025-10-10 19:10:02 +0200 |
---|---|---|
committer | filip <“filip.rabiega@gmail.com”> | 2025-10-10 19:10:02 +0200 |
commit | 807de46d3a3cbef9a3c3c104f6db87b142e6eed5 (patch) | |
tree | 61a1a9bc26daad623ce6c04bb66ae39133ef0261 /inpath | |
parent | 08204fc9b9f63015a1dc083b471c6839818eeb59 (diff) | |
download | chadscripts-807de46d3a3cbef9a3c3c104f6db87b142e6eed5.tar.gz chadscripts-807de46d3a3cbef9a3c3c104f6db87b142e6eed5.tar.bz2 chadscripts-807de46d3a3cbef9a3c3c104f6db87b142e6eed5.zip |
used shfmt
Diffstat (limited to 'inpath')
-rwxr-xr-x | inpath | 59 |
1 files changed, 29 insertions, 30 deletions
@@ -1,44 +1,43 @@ #!/bin/sh -in_path () { - cmd=$1 path=$2 res=1 - IFS=":" - - for dir in $path; - do - if [ -x "$dir/$cmd" ]; then - res=0 - break - fi - done - - return $res +in_path() { + cmd=$1 path=$2 res=1 + 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 +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 + 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" ;; +0) echo "$1 found in PATH" ;; +1) echo "$1 not found or not executable" ;; +2) echo "$1 not found in PATH" ;; esac exit 0 |