#!/usr/bin/csh -f

if ( $#argv == 0 ) then
  echo "Usage: $0 <programName> [<program arguments>]"
  exit 1 
endif

set progName = $argv[1]
shift
echo Searching path for $progName ...
foreach dir ( $path )
  if ( -d $dir ) then
    if ( -r $dir ) then
      if ( -e $dir/$progName ) then
        if ( -x $dir/$progName ) then
          if ( $?theProg == 0 ) set theProg = $dir/$progName
          echo $dir/$progName found ...
        else
          echo $dir/$progName exists, but is not executable ...
        endif
      endif
    else
      echo Unable to read $dir
    endif
  else
    echo Unable to find path directory $dir
  endif
end
if ( $?theProg ) then
  echo Executing "$theProg $argv" ...
  $theProg $argv
  echo $theProg returned status = $status
else
  echo $progName not found.
endif
