-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_programs.sh
More file actions
executable file
·51 lines (43 loc) · 868 Bytes
/
find_programs.sh
File metadata and controls
executable file
·51 lines (43 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
in_path() {
cmd=$1
path=$2
res=1
oldIFS=$IFS
IFS=":"
for directory in "$path"
do
echo $directory
if [ -x $directory/$cmd ] ; then
echo $directory/$cmd
res=0
fi
done
IFS=$oldIFS
return $result
}
checkForCmdInPath() {
var=$1
if [ "$var" != "" ]; then
# using variable slicing to isolate the first character.
if [ "${var:0:1}" = "/" ]; then
if [ ! -x $var ]; then
return 1
fi
elif ! in_path $var "$PATH"; then
return 2
fi
fi
}
# main
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