Date: Fri, 3 May 2024 09:18:09 -0400
From: Chet Ramey <[email protected]>
Message-ID: <[email protected]>
| How is this any different than
|
| PATH=$BASH_IMPORT_PATH:$PATH source
| or
| PATH=$BASH_IMPORT_PATH source
|
| You could force the latter if you are sure that the sourced files will
| not attempt to run external commands.
Another safer way might be
findfile()
{
local - P IFS=:
case "$1" in
*/*) printf %s "$1"; return;;
esac
set -f
for P in ${BASH_IMPORT_PATH:-.}
do
if test -f "${P:-.}/$1"
then
printf %s "${P:-.}/$1"
return
fi
done
printf %s "$1"
}
And then
. "$(findfile whatever)"
relying upon the error message from '.' if whatever isn't found (and
use whatever name you like instead of "findfile").
An alternative I hate to even mention, as it is so hacky (and has
mostly been deleted from most of its descendants) is the ash shell
%func PATH hack: if an entry in $PATH ends in %func and the search for a
command reaches that entry, and a file exists in the directory named
(with the "%func" deleted) with the name of the command being sought,
then the shell will (would) source that file, and if after doing that
a function with the name of the command being sought had appeared, then
run that function as the command. Otherwise, just continue with the
PATH search (more than one %func entry was possible).
So I agree, "import" is definitely not needed, and if it were
really to be deemed useful functionality, "import" is the wrong name.
kre