Bash scripts can be hard to get right so reusing proven solutions as shell script libraries is of immense value. However, the existing shell script sourcing mechanisms are suboptimal for this task. The source builtin uses the PATH variable for resolving file names which means they would have to be placed alongside normal executables which could cause confusion.
The simplest possible solution would be to add a special operating mode to the existing source builtin to make it behave in the desired way. However, that would overload an already overloaded builtin even further. There are already complexities in how it works due to POSIX compliance. This would add to those complexities. This patch set introduces a new "import" builtin which behaves just like the source builtin but only looks up executables in the BASH_IMPORT_PATH variable. Care was taken not to duplicate existing code. The needed functionality was split off from existing code and into parameterized helper functions that both the old and the new code could use. Matheus Afonso Martins Moreira (4): builtins: extract file content executor function findcmd: parameterize path variable in functions findcmd: define the user import finder function builtins: add import builtin AUTHORS | 1 + MANIFEST | 1 + Makefile.in | 4 +- builtins/Makefile.in | 6 ++- builtins/common.c | 64 ++++++++++++++++++++++++++++ builtins/common.h | 1 + builtins/import.def | 99 ++++++++++++++++++++++++++++++++++++++++++++ builtins/source.def | 62 ++------------------------- findcmd.c | 37 +++++++++++------ findcmd.h | 1 + 10 files changed, 202 insertions(+), 74 deletions(-) create mode 100644 builtins/import.def -- 2.44.0