Where am I (csh)

Mark Komarinski mkomarinski at wayga.org
Wed Jan 15 14:57:09 EST 2003


On Wed, Jan 15, 2003 at 02:44:44PM -0500, Derek Martin wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On Wed, Jan 15, 2003 at 02:20:12PM -0500, Mark Komarinski wrote:
> > Without getting into the "why are you using X to do the job":
> 
> Who, us?  ;-)
> 
> > I've got a csh script in an arbitrary location.  But I need to know
> > from within the script where it exists in the directory structure.  The
> > reason for that is I need to source a file from within that same
> > directory (where the script is).  If I look for cwd or pwd, I get the
> > directory my shell was when when I ran the script, not where the
> > script itself is located.
> 
> I'm not that familiar with csh, but AFAIK this can not be done; at
> least not directly.  The only way the script will know where it lives
> is if you tell it explicitly on the command line, either by specifying
> the full path (it'll be in the equivalent of argv[0] if csh makes that
> available), or by including the directory as a command-line option.
> 
> A possible solution is to use the which command from within the script
> to determine the path to the script.  Obviously, if the path to the
> script is different from within the script as compared to when the
> script is started (though I can't imagine why this would be), then it
> won't work.
> 
> > As an additional condition, I can't use anything on the local system, as
> > the script will be run over NFS to various systems (hence one of the
> > reasons it's arbitrary).  And it has to be csh, no tcshisms.
> 
> I'm not sure I understand why this is a problem...  the script is
> still going to run on machine X, wherever it lives; it should be able
> to use any of the commands local to machine X.

I could do that, but I don't want to configure 30+ machines every time
I need to make a change.

Perhaps I should go into more detail of this script.  We have an internal
project which combines a bunch of software used by people with very long
sets of initials after their names (PhD, BS, MS, MD, etc.) doing things
I will never understand (xray crystallography - did I even spell that
right?).

There is an existing collection of software available for Linux and
SGIs being distributed by a different lab and most of the labs I
administer are either using it, or want to.  The problem with said
distribution is there is a 35k cshrc file that has to be sourced
when the user logs in to set up the various environmental variables
and paths to let them use the applications.

The problem is that as the software is distributed now, you have to
create a link in the root directory to the location of where
the software actually sits (which is arbitrary due to NFS and
how things are configured).  So on each machine that each user
needs access to the collection, I have to make the symbolic link.
That's annoying.  There has to be a way for a script to know where it
is and take advantage of that fact.  But the cshrc file has to remain
as it is, as the distributors of the software will change it as new
versions of software packages come out.  So I have have the script know
where it's located when it runs so it can load up a configuration file
for that instance of the collection of software, which again is at
an arbitrary location.  For reasons beyond my (current) control, this
is all done in csh.  Can't change it, but I may be able to write a bash
version, but that won't help the existing users who don't want to
change from csh to bash.

Whew.

Did I ever mention that life in academics is a lot different from life
in the business world?

-Mark
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.gnhlug.org/mailman/private/gnhlug-discuss/attachments/20030115/c35e4be4/attachment.bin


More information about the gnhlug-discuss mailing list