[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Determining the current path of a sourced script
From: |
Chet Ramey |
Subject: |
Re: Determining the current path of a sourced script |
Date: |
Wed, 13 Mar 2002 08:53:30 -0500 |
> I have a bash script that will be sourced rather than run. Is there
> anyway for the script to determine its location (pathname)?
>
> Specifically, in my .bashrc I have:
>
> if [ -f /devel/bashrc ]; then
> . /devel/bashrc
> fi
>
> Is there any way for /devel/bashrc to determine what directory it is
> in? The reason is that /devel/bashrc is a delivered file and it might
> wind up in any directory (and probably not /devel) and it needs to
> know where itself is so it can set environment variables correctly.
>
> Obviously $0 doesn't help, because that contains "bash".
Only if you tell it:
if [ -f /devel/bashrc ]; then
DEVEL_BASHRC=/devel/bashrc
. ${DEVEL_BASHRC}
fi
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)
Chet Ramey, CWRU chet@po.CWRU.Edu http://cnswww.cns.cwru.edu/~chet/