help-bash
[Top][All Lists]
Advanced

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

[Help-bash] Finding full path of sourced script


From: Suvayu Ali
Subject: [Help-bash] Finding full path of sourced script
Date: Tue, 4 Sep 2012 13:15:00 +0200
User-agent: Mutt/1.5.21 (2011-07-01)

Hi Bash users and experts,

I wanted to find the full path of a sourced script.  I cannot use
something like `basename $0` as $0 points to $BASH.  I came across
$BASH_SOURCE, which seems to do the trick.  But I don't quite understand
how that translates from the following snippet from the info page (since
there are no functions involved here).


`BASH_SOURCE'
     An array variable whose members are the source filenames where the
     corresponding shell function names in the `FUNCNAME' array
     variable are defined.  The shell function `${FUNCNAME[$i]}' is
     defined in the file `${BASH_SOURCE[$i]}' and called from
     `${BASH_SOURCE[$i+1]}'


Is there a better alternative?  If not, can someone help me understand
my specific case, when I'm not inside a function?

Thanks,

-- 
Suvayu

Open source is the future. It sets us free.



reply via email to

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