[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: proposed BASH_SOURCE_PATH
From: |
konsolebox |
Subject: |
Re: proposed BASH_SOURCE_PATH |
Date: |
Thu, 4 Jul 2024 02:37:11 +0800 |
On Mon, Jul 1, 2024 at 10:56 PM Chet Ramey <chet.ramey@case.edu> wrote:
>
> On 6/26/24 5:59 AM, konsolebox wrote:
> > On Tue, Jun 25, 2024 at 11:14 PM Chet Ramey <chet.ramey@case.edu> wrote:
> >>
> >> On 6/19/24 6:12 PM, konsolebox wrote:
> >>
> >>> Alternatively, have BASH_SOURCE always produce real physical paths
> >>> either by default or through a shopt.
> >>
> >> This is the best option. I don't think changing bash to do this by default
> >> would have negative side-effects.
> >
> > That's great. So will this be implemented soon or will you consider
> > other lazy alternatives first?
> >
> > I already made a patch for it here:
> > https://gist.github.com/konsolebox/a908cf13e511abdf05daec89a9cbdd8d#file-bash-source-real-patch
>
> Should your patch make sure that paths supplied to source/. push the full
> pathname into BASH_SOURCE? It only handles the name of a shell script and
> leaves the pathname associated with a shell function alone.
Sorry it took me a while to reply. Should this be enough?
https://gist.github.com/konsolebox/a908cf13e511abdf05daec89a9cbdd8d#file-bash-source-real-patch
(Same URI but updated; old version in revisions)
There seem to be three places where "bash_source_a" is updated
(evalfile.c, execute_cmd.c, and shell.c), but only the ones in
evalfile.c and shell.c seem to need updating. The one in
execute_cmd.c copies the source's path from the function's definition
but when the functions are defined, the source's path is also just
copied from bash_source_a as shown in make_function_def's code:
temp->source_file = 0;
#if defined (ARRAY_VARS)
GET_ARRAY_FROM_VAR ("BASH_SOURCE", bash_source_v, bash_source_a);
if (bash_source_a && array_num_elements (bash_source_a) > 0)
temp->source_file = array_reference (bash_source_a, 0);
#endif
I tested it with the following files:
a.sh
--------------------
declare -p BASH_SOURCE
. ./x/b.sh
a() {
declare -p BASH_SOURCE
}
a
--------------------
x/b.sh
--------------------
declare -p BASH_SOURCE
--------------------
Running ../bash ./a.sh shows the following with similar paths replaced
with '/path/to/bash':
--------------------
declare -a BASH_SOURCE=([0]="/path/to/bash/t/a.sh")
declare -a BASH_SOURCE=([0]="/path/to/bash/t/x/b.sh" [1]="/path/to/bash/t/a.sh")
declare -a BASH_SOURCE=([0]="/path/to/bash/t/a.sh" [1]="/path/to/bash/t/a.sh")
--------------------
--
konsolebox
- Re: proposed BASH_SOURCE_PATH, Chet Ramey, 2024/07/01
- Re: proposed BASH_SOURCE_PATH,
konsolebox <=
- Re: proposed BASH_SOURCE_PATH, Chet Ramey, 2024/07/03
- Re: proposed BASH_SOURCE_PATH, konsolebox, 2024/07/03
- Re: proposed BASH_SOURCE_PATH, alex xmb sw ratchev, 2024/07/03
- Re: proposed BASH_SOURCE_PATH, Chet Ramey, 2024/07/07
- Re: proposed BASH_SOURCE_PATH, alex xmb sw ratchev, 2024/07/07
- Re: proposed BASH_SOURCE_PATH, Greg Wooledge, 2024/07/07
- Re: proposed BASH_SOURCE_PATH, Chet Ramey, 2024/07/10
- Re: proposed BASH_SOURCE_PATH, konsolebox, 2024/07/11
- Re: proposed BASH_SOURCE_PATH, Chet Ramey, 2024/07/18
- Re: proposed BASH_SOURCE_PATH, konsolebox, 2024/07/18