rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* pathos script
@ 1993-07-28  2:15 Alan Watson
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Watson @ 1993-07-28  2:15 UTC (permalink / raw)
  To: rc

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: pathos script
@ 1993-07-28 13:21 Alan Watson
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Watson @ 1993-07-28 13:21 UTC (permalink / raw)
  To: rc

Oops.  That first `echo >[2=1]' should be `echo >[1=2]'.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1993-07-28 13:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-07-28  2:15 pathos script Alan Watson
1993-07-28 13:21 Alan Watson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).