"Fossies" - the Fresh Open Source Software Archive

Member "mpr-2.8/mprwhich" (6 Jun 2005, 1013 Bytes) of package /linux/misc/old/mpr-2.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 
    3 symlink=
    4 
    5 try()
    6 {
    7     if test ! -d "$1" -a -x "$1"; then
    8         if test ! -r "$1"; then
    9             echo mprwhich: error: cannot read "$1" >&2
   10             exit
   11         fi
   12         case "$symlink" in
   13         "") echo "$1"
   14             exit 0;;
   15         esac
   16         f=`file "$1"`
   17         case "$f" in
   18         *"symbolic link"*)
   19             l=`echo "$f" | awk '{print $NF}'`
   20             case "$l" in \`*\') l=`echo "$l" | tr -d "'\140"`;; esac    # remove trash chars `'
   21             case "$l" in
   22             /*) aout="$l";;
   23             *)  aout=`echo "$1" | awk -F/ '{OFS="/"}{$NF=""; print}'`"$l";;
   24             esac
   25             exec mprwhich "$aout"
   26             echo mprwhich: error: cannot exec self >&2
   27             exit 1;;
   28         *)  echo "$1"
   29             exit 0;;
   30         esac
   31     fi
   32 }
   33 
   34 for arg in "$@"; do
   35     case "$1" in
   36     -s) symlink=true;;
   37     --) shift; break;;
   38     *)  break;;
   39     esac
   40     shift
   41 done
   42 
   43 case "$#" in
   44 1)  ;;
   45 *)  echo usage: mprwhich [-s] program >&2
   46     exit 1;;
   47 esac
   48 
   49 case "$1" in
   50 /*|./*) try "$1"
   51     echo mprwhich: error: "$1" is not executable >&2
   52     exit 1;;
   53 esac
   54 
   55 for d in `echo "$PATH" | sed 's/:/ /g'`; do
   56     try "$d/$1"
   57 done
   58 
   59 echo mprwhich: error: cannot find "$1" in "$PATH" >&2
   60 exit 1