#!/bin/sh # moved-command 1.11 # by Adam M. Costello # # # Put this in the old place of a command that has moved, to notify # people if they don't have the real command in their PATH. If they # already have the command somewhere else in their path, this script # exec's it transparently. # Configure this line: newdir=/directory/containing/command # findother # # Searches PATH and outputs the pathname of the first executable with # the given basename which is *not* located in the given directory. # Outputs nothing if nothing is found. Returns 0 if something is found, # 1 otherwise. findother() { baddir=$1 base=$2 badrealdir=`(cd "$baddir" && pwd) 2>&-` oldIFS=$IFS IFS=:$oldIFS set -- $PATH IFS=$oldIFS for bindir do realbindir=`(cd "$bindir" && pwd) 2>&-` if [ "$realbindir" != "$badrealdir" -a -x "$bindir/$base" ]; then echo "$bindir/$base" return 0 fi done return 1 } # Main script starts here. mydir=`dirname "$0"` mybase=`basename "$0"` if other=`findother "$mydir" "$mybase"`; then exec "$other" ${1+"$@"} fi if [ -x "$newdir/$mybase" ]; then echo "$mybase has moved to $newdir/$mybase" else echo "$mybase is not in $mydir anymore" fi