NBash
51 строка · 638.0 Байт
1#!/bin/bash
2
3in_path()
4{
5command=$1
6our_path=$2
7result=1
8oldIFS=$IFS
9IFS=":"
10
11for directory in $our_path
12do
13if [ -x "$directory/$command" ]; then
14result=0
15fi
16done
17
18IFS=$oldIFS
19return $result
20}
21
22check_command_in_PATH()
23{
24var=$1
25
26if [ "$var" != "" ]; then
27if [ "${var:0:1}" = "/" ]; then
28if [ ! -x $var ]; then
29return 1
30fi
31elif ! in_path "$var" "$PATH"; then
32return 2
33fi
34fi
35}
36
37if [ $# -ne 1 ]; then
38echo "Usage: $0 command" >&2
39exit 1
40fi
41
42check_command_in_PATH "$1"
43
44
45case $? in
460) echo "$1 found in PATH";;
471) echo "$1 not found or not executable";;
482) echo "$1 not found in PATH";;
49esac
50
51exit 0