For various reasons I would like to be able to source a series of files in background and wait for them all to finish:
source ./my_file_1.sh &
source ./my_file_2.sh &
...
# etc
wait
But, while this does sort of work, they are sourced in sub-shells instead of the current shell’s context:
my_file_1.sh
:
foo_bar() {
echo "hi"
}
main_source_file.sh
:
source ./my_file_1.sh &
wait
# zsh: command not found: foo_bar
foo_bar
Is there a way to source files in the background or in parallel while still having them modify the current shell context?