[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: proposed BASH_SOURCE_PATH
From: |
Chet Ramey |
Subject: |
Re: proposed BASH_SOURCE_PATH |
Date: |
Wed, 15 May 2024 11:26:57 -0400 |
User-agent: |
Mozilla Thunderbird |
On 5/14/24 4:10 AM, konsolebox wrote:
On Tue, May 14, 2024 at 2:09 PM Martin D Kealey <martin@kurahaupo.gen.nz> wrote:
1. I therefore propose that where a relative path appears in
BASH_SOURCE_PATH, it should be taken as relative to the directory
containing $0 (after resolving symlinks), rather than relative to $PWD.
This implies only the directory where the main script is located will
be used, correct?
Hopefully Bash already has a deterministic way of knowing the
directory the main script is located.
How deterministic do you need? Bash sets $0 and ${BASH_SOURCE[0]} to the
script name passed as an argument. It's easy enough to write a function
that canonicalizes that, or to use `realpath' as others have suggested.
(There is a `realpath' loadable builtin.)
Once you've canonicalized it, you can use ${FULLPATH%/*} to get the
directory name.
2. Search BASH_SOURCE_PATH when any relative path is given, not just a path
that lacks a '/', so that libraries can be organized into subdirectories.
I disagree with this. Paths beginning with ./ or ../ should be
considered explicit and not searched in BASH_SOURCE_PATH.
Those are absolute pathnames.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
Re: proposed BASH_SOURCE_PATH,
Chet Ramey <=
Re: proposed BASH_SOURCE_PATH, Koichi Murase, 2024/05/14
Re: proposed BASH_SOURCE_PATH, Léa Gris, 2024/05/14
Re: proposed BASH_SOURCE_PATH, Chet Ramey, 2024/05/15
Re: proposed BASH_SOURCE_PATH, Koichi Murase, 2024/05/15
Re: proposed BASH_SOURCE_PATH, Chet Ramey, 2024/05/15