Reputation: 2784
I have a bash file with a list of functions. If I add to other script the header:
source /myusefulfuncionlist.sh
they can call the functions inside the file.
Is there a way to avoid this add to keep it DRY? If I add to /etc/bash.bashrc I can access function from user shell but scripts won't.
Upvotes: 1
Views: 721
Reputation: 141010
From bash manual startup files:
Invoked non-interactively
When Bash is started non-interactively, to run a shell script, for example, it looks for the variable BASH_ENV in the environment, expands its value if it appears there, and uses the expanded value as the name of a file to read and execute. ...
Edit /etc/environment
and add:
BASH_ENV=/fullpathto/myusefulfuncionlist.sh
and relogin and non-interactive shells should pick up your source file.
Upvotes: 2