head 1.1; access; symbols; locks ahuxley:1.1; strict; comment @# @; 1.1 date 2001.01.16.07.51.42; author ahuxley; state Exp; branches; next ; desc @COMMAND SWITCHER @ 1.1 log @Initial revision @ text @#!/usr/bin/ksh PROGNAME=`basename $0` error() { echo "$PROGNAME: ERROR: $1" >&2 exit 1 } warning() { echo "$PROGNAME: WARNING: $1" >&2 } case "$1" in --say) echo "$2" exit 0 ;; esac # First verify that we are using a 'which' command capable of telling us all # we need to know. [ "X`which --say test 2>&1`" != Xtest ] && error "can't find good 'which' command" # If *this* program is the first found prog with this name, then the second # one is the real one, otherwise we pick the first found one with this name. if [ "X`$PROGNAME --say test 2>&1`" = Xtest ]; then REAL_PROGRAM=`which -a -r 2 $PROGNAME` else REAL_PROGRAM=`which $PROGNAME` fi eval SWITCHED_PROGRAM=\$SWITCHED_${PROGNAME} if [ "X$SWITCHED_PROGRAM" = X ]; then exec $REAL_PROGRAM "$@@" elif [ "X$`which $SWITCHED_PROGRAM`" = X ]; then warning "couldn't find \$SWITCHED_${PROGNAME} ($SWITCHED_PROGRAM)" exec $REAL_PROGRAM "$@@" else exec $SWITCHED_PROGRAM "$@@" fi @