Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: What's the equivalent of ${BASH_SOURCE[0]}?
- X-seq: zsh-users 29738
- From: Felipe Contreras <felipe.contreras@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: What's the equivalent of ${BASH_SOURCE[0]}?
- Date: Sat, 16 Mar 2024 03:33:25 -0600
- Archived-at: <https://zsh.org/users/29738>
- In-reply-to: <CAH+w=7ZSfgKN19A8rY1DGnz+Aj_iOERvNaLX=Liye0Co9O-tvg@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CAMP44s3JuCYoNYQEgVUMwPLwGb7AJSzFF=KLe00v0g_q0z1Kaw@mail.gmail.com> <CAH+w=7YedsQCk56Bvygc_NvsByDJf_MWK57XZYEoO4Xtx1eXww@mail.gmail.com> <CAMP44s0nmNB7zXorO1Vh7sPGQqATv46p8+c7Pn7_0r-1FAPNqw@mail.gmail.com> <CAH+w=7ZSfgKN19A8rY1DGnz+Aj_iOERvNaLX=Liye0Co9O-tvg@mail.gmail.com>
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