bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Determining the current path of a sourced script


From: Tony
Subject: Re: Determining the current path of a sourced script
Date: 13 Mar 2002 07:05:58 -0800

Ben,

Thanks for your response.

Succint reply: No, that doesn't work.

Verbose reply:
PWD gives me the path to the current working directory of the process
which called the script. When initializing bash (e.g. when logging
in), which is the most common time one's $HOME/.bashrc is executed,
the current working directory is $HOME. So, in this instance, $PWD ==
$HOME inside /devel/bashrc when it is sourced by $HOME/.bashrc. I need
for /devel/bashrc to magically detect that it is in /devel (or
wherever the evil user has placed it).

I need something like __FILE__ in C.

All I can think to do, since the user has to modify their .bashrc
anyway (to source my bashrc), is to force the user to also export an
environment variable indicating where they placed my bashrc. I don't
want to tell the user to edit my bashrc, because then they will be
tempted to muck with everything else in there.

A programmer's life would be much simpler if there were no users.

Cheers,
Tony

ben@wblogan.net (Ben Logan) wrote in message 
news:<20020313062455.A12497@newcreature.org>...
> On Tue, Mar 12, 2002 at 03:08:39PM -0800, Tony wrote:
> > I have a bash script that will be sourced rather than run. Is there
> > anyway for the script to determine its location (pathname)?
> 
> As long as you don't "cd" first, wouldn't the PWD environment variable
> do the trick?
> 
> Regards,
> Ben



reply via email to

[Prev in Thread] Current Thread [Next in Thread]