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 29736
- 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: Fri, 15 Mar 2024 10:28:11 -0600
- Archived-at: <https://zsh.org/users/29736>
- In-reply-to: <CAH+w=7YedsQCk56Bvygc_NvsByDJf_MWK57XZYEoO4Xtx1eXww@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CAMP44s3JuCYoNYQEgVUMwPLwGb7AJSzFF=KLe00v0g_q0z1Kaw@mail.gmail.com> <CAH+w=7YedsQCk56Bvygc_NvsByDJf_MWK57XZYEoO4Xtx1eXww@mail.gmail.com>
On Wed, Mar 6, 2024 at 11:16 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Wed, Mar 6, 2024 at 1:57 PM Felipe Contreras
> <felipe.contreras@xxxxxxxxx> wrote:
> >
> > But what if someone wants to do the opposite? Use the zsh $0 even if
> > POSIX_ARGZERO is on?
>
> Of course the zsh $0 depends on the setting of FUNCTION_ARGZERO, but I
> know what you mean.
I meant the name of the source script file, which I suppose it's
FUNCTION_ARGZERO when you aren't inside a function.
In other words: ${BASH_SOURCE[0]}.
> > So far I've found that ${(%):-%N} is the best option, but I wonder if
> > there is a better one.
>
> $funcstack[1] would be the other option, unless for some odd reason
> the zsh/parameter module is not available.
>
> An advantage of $funcstack is that you can use
> ${${(@)funcstack:#'(anon)'}[1]} to get the name of the nearest
> non-anonymous function.
Actually I realized that it's ${(%):-%x} what I'm looking for, since
that is the best equivalent for ${BASH_SOURCE[0]}.
According to StackOverflow there are no better options [1].
Cheers.
[1] https://stackoverflow.com/a/28336473/10474
--
Felipe Contreras
Messages sorted by:
Reverse Date,
Date,
Thread,
Author