1

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.

0

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.