Dmitry Telenkov 11 månader sedan
förälder
incheckning
1d265ea2ad
3 ändrade filer med 70 tillägg och 0 borttagningar
  1. 49 0
      bash/inpath.sh
  2. 5 0
      bash/intro
  3. 16 0
      bash/test.sh

+ 49 - 0
bash/inpath.sh

@@ -0,0 +1,49 @@
+#!/bin/bash
+# inpath -- Проверяет допустимость пути к указанной программе
+# или ее доступность в каталогах из списка PATH
+
+in_path()
+{
+
+  cmd=$1 ourpath=$2 result=1  
+  oldIFS=$IFS IFS=":"
+
+  for directory in "$ourpath"
+  do
+    if [ -x $directory/$cmd ] ; then
+      result=0  # Если мы здесь, значит, команда найдена
+    fi 
+  done
+  
+  IFS=$oldIFS
+  return $result
+}
+
+checkForInPath()
+{
+  var=$1
+
+  if [ "$var" != "" ] ; then
+    if [ "${var:0: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
+
+checkForInPath "$1"
+case $? in
+  0 ) echo "$1 found in PATH" ;;
+  1 ) echo "$1 not found or not executable" ;;
+  3 ) echo "$1 not found in PATH" ;;
+esac
+
+exit 0

+ 5 - 0
bash/intro

@@ -0,0 +1,5 @@
+#!/bin/bash
+echo "hello world"
+echo $(which neqn)
+cat $(which neqn)
+

+ 16 - 0
bash/test.sh

@@ -0,0 +1,16 @@
+#!/bin/bash
+
+echo "this is test"
+
+func1()
+{
+  echo "this is func1"
+}
+
+func2()
+{
+  echo "this is func2"
+}
+
+echo "$#"
+