title: Bash script to find the path of an executable
body: <p>EDIT: I KNOW THIS IS REDUNDANT, IT IS HOMEWORK, I HAVE WRITTEN MY OWN CODE AND NEED HELP TROUBLESHOOTING></p>
  
  <p>As stated, I must write a BASH script to determine whether an executable file is in the users path. </p>
  
  <p>such that if you type<br>
      ./findcmd ping it returns /bin/ping</p>
  
  <p>I have some code written, But it does not properly work and I hope someone can help me troubleshoot. When I type ./findcmd ping it just returns my file does not exist.(with any other file I try as well that I know exists.)</p>
  
  <pre><code>#!/bin/bash
  #
  # Invoke as ./findcmd command
  #
  # Check for argument
  if [[ $# -ne 1 ]]
   then
      echo 'useage: ./findcmd command'
      exit 1
  fi
  #
  # Check for one argument
  if [[ $# -eq 1 ]]
   then
       pathlist=`echo $PATH | tr ':' ' '`
       for d in $pathlist;
            do
               if [[ ! -d $d || ! -x $d || ! -r $d ]]
                 then
                     echo 'You do not have read end execute
                            permissions!'
                     exit 2
                fi
                if [[ $(find $d -name $1 -print | wc -l) -ne 0 ]]
                     then
                           echo 'The file does not exist in the PATH!'
                            exit 0
  
               fi
          done
  fi
  
  exit 0
  #
  #
  </code></pre>