From 6366167443dbac5e96dcd33b99e160a3321ab71a Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Wed, 8 Jun 2022 02:44:09 +0200 Subject: [PATCH] gave sheelutils a more appropriate name and added which --- {miniutils => shellutils}/groups | 0 shellutils/which | 57 ++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) rename {miniutils => shellutils}/groups (100%) mode change 100644 => 100755 create mode 100755 shellutils/which diff --git a/miniutils/groups b/shellutils/groups old mode 100644 new mode 100755 similarity index 100% rename from miniutils/groups rename to shellutils/groups diff --git a/shellutils/which b/shellutils/which new file mode 100755 index 0000000..e53e532 --- /dev/null +++ b/shellutils/which @@ -0,0 +1,57 @@ +#!/bin/sh +internal_path="$(echo $PATH | sed -e 's/:/\n/g')" + +while true; do + if getopts "ac:h" arg; then + true # do nothing + else + break + fi + case $arg in + a) + all="yes" + shift + ;; + c) + internal_path="$(echo $OPTARG | sed -e 's/:/\n/g')" + shift 2 + ;; + h) + echo "Usage: $0 [-a] [-c ] " + echo \ +'Options: + -a return all results if multiple found + -c search in the specified path instead of $PATH + -h display this message' + echo \ +"Exit codes: + 0 found + 1 not found + 2 error" + exit 0 + ;; + ?) + echo "Usage: $0 [-a] [-c ] " + exit 2 + ;; + esac +done + +IFS=' +' +for directory in $internal_path; do + if [ -e "$directory/$1" ]; then + echo "$directory/$1" + if [ "$all" = "yes" ]; then + found="yes" + else + exit 0 + fi + fi +done + +if [ "$found" = "yes" ]; then + exit 0 +else + exit 1 +fi