Yes. This is how the .
/source
operator works.
From the spec:
The shell shall execute commands from the file in the current environment.
If file does not contain a <slash>, the shell shall use the search path specified by PATH to find the directory containing file. Unlike normal command search, however, the file searched for by the dot utility need not be executable. If no readable file is found, a non-interactive shell shall abort; an interactive shell shall write a diagnostic message to standard error, but this condition shall not be considered a syntax error.
So when you use source file.sh
the shell searches in the $PATH
but when you use source dir/file.sh
the $PATH
lookup is skipped and dir
is assumed to be relative to the current directory.
To do this sort of thing (internally to main.sh
or major.sh
) you could use Can a Bash script tell what directory it's stored in? to find the appropriate absolute path to use.
For general use you are going to need to stick them all in $PATH
or source
them from absolute/etc. paths.