bug-bash
[Top][All Lists]
Advanced

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

Re: proposed BASH_SOURCE_PATH


From: Will Allan
Subject: Re: proposed BASH_SOURCE_PATH
Date: Thu, 20 Jun 2024 02:51:39 +0000 (UTC)

Thanks for clarifying! I wondered if I was missing something, but kept seeing 
`${BASH_SOURCE[0]/%/*}` suggested in the thread, which I pointed out is flawed.

I guess what I want is a "BASH_SOURCE_DIR" variable or something like it, 
mainly to avoid the boilerplate, variable, and/or command substitution in each 
of my main scripts.

Note that ShellCheck uses a similar SCRIPTDIR to help locate sourced files 
relative to the main script:

https://github.com/koalaman/shellcheck/issues/1577

-Will

On Wednesday, June 19, 2024 at 03:13:59 PM PDT, konsolebox 
<konsolebox@gmail.com> wrote: 





On Thu, Jun 20, 2024 at 4:05 AM Will Allan <billyzkid@yahoo.com> wrote:
> But, I still don’t like it. I have to start off each script with a slow 
> command substitution (subshell) which introduces a variable that I don’t 
> really want, but it’s too slow to do this repeatedly:

I agree.


> source -- "${BASH_SOURCE_PATH}/../lib/foo.sh"


You misunderstood the use of BASH_SOURCE_PATH though.  It's proposed
to be an alternative to PATH which is only respected by source.  I
suggest another name.  And that is BASH_SOURCE_REAL.

Alternatively, have BASH_SOURCE always produce real physical paths
either by default or through a shopt.

Any additional feature that doesn't allow loading a script relative to
the caller without external help is practically useless.


-- 
konsolebox


reply via email to

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