From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from oldp.astro.wisc.edu ([128.104.39.15]) by hawkwind.utcs.toronto.edu with SMTP id <2752>; Tue, 27 Jul 1993 22:15:19 -0400 Received: by oldp.astro.wisc.edu (5.65/DEC-Ultrix/4.3) id AA09362; Tue, 27 Jul 1993 21:15:12 -0500 Message-Id: <9307280215.AA09362@oldp.astro.wisc.edu> To: rc@hawkwind.utcs.toronto.edu Subject: pathos script Date: Tue, 27 Jul 1993 22:15:11 -0400 From: Alan Watson X-Mts: smtp About a year ago John Mackin posted a pathos script. The idea was that you could use it in a front-end version of a standard command to invoke the a command further down the path. John noted that there was a problem if if a script got exec-ed with a relative pathname. I think I've come up with a way to get around this. All of those pwds can take a little while, but the additional bullet-proofing seems worthwhile to me as it doesn't cause much of a burden in the normal case. I prefer to use: exec `{ pathos $0 } $* as it alleviates the need to protect variables. On failure, pathos prints an error message on stderr and false on stdout, which I think is quite a nice way to deal with that situation. BTW, John, why did you choose the name `pathos'? Alan. #! /tmp/alan/bin/rc -- if ( ! ~ $#* 1 ) { echo >[2=1] usage: pathos path echo false exit 1 } thisdir = `{ dirname $1 } thisbase = `{ basename $1 } # shift $path past $thisdir * = $path if ( ~ $thisdir $* ) { while ( ! ~ $thisdir $1 ) { shift } } else { thisdir = `{ builtin cd $thisdir ; builtin pwd } while ( ! ~ $#* 0 && ! ~ $thisdir `{ builtin cd $1 ; builtin pwd } ) { shift } if ( ~ $#* 0 ) { echo >[1=2] pathos: unable to find $thisdir in path echo false exit 1 } } shift # look for executable $thisbase in remainder of $path # if whatis succeeds, it prints the path on stdout for us while ( ! ~ $#* 0 ) { if ( whatis $1/$thisbase >[2=] ) { exit 0 } shift } echo >[1=2] pathos: unable to find $thisbase echo false exit 1 # end-of-file