rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
From: Alan Watson <alan@oldp.astro.wisc.edu>
To: rc@hawkwind.utcs.toronto.edu
Subject: pathos script
Date: Tue, 27 Jul 1993 22:15:11 -0400	[thread overview]
Message-ID: <9307280215.AA09362@oldp.astro.wisc.edu> (raw)

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


             reply	other threads:[~1993-07-28  2:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-07-28  2:15 Alan Watson [this message]
1993-07-28 13:21 Alan Watson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9307280215.AA09362@oldp.astro.wisc.edu \
    --to=alan@oldp.astro.wisc.edu \
    --cc=rc@hawkwind.utcs.toronto.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).