Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: What's the equivalent of ${BASH_SOURCE[0]}?



On Fri, Mar 15, 2024 at 11:07 PM Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Fri, Mar 15, 2024 at 9:28 AM Felipe Contreras
> <felipe.contreras@xxxxxxxxx> wrote:
> >
> > I meant the name of the source script file
>
> Like $ZSH_SCRIPT ?

No. Le'ts get the terminology straight from zsh manpages:

In describing $0 it says:

  If the FUNCTION_ARGZERO option is set, $0 is set ... upon entry to a
  sourced script to the name of the script

So when you do "source ./lib.sh" inside that script "./lib.sh" is the
name of the sourced script.

On the other hand this is the description of $ZSH_SCRIPT:

  If zsh was invoked to run a script, this is the name of the script

So if "lib.sh" is sourced from "foo.sh", then $ZSH_SCRIPT would be
"foo.sh", whereas ${BASH_SOURCE[0]} would be "./lib.sh".

Both are "names of a script", but one is an "invoked script" and the
other is a "sourced script". Correct?

I'm looking for the name of the *sourced* script. So it would be
something like $ZSH_SOURCE (if it existed).

-- 
Felipe Contreras




Messages sorted by: Reverse Date, Date, Thread, Author