1

All my scripts depend on some env vars & shell functions that effectively form a library.

Is there a system-wide place where such bootstrapping code could be placed so it's included in every shell session, regardless if it's running in a non-interactive script or user-facing shell? Eg I'd like to have following function definition to be globally available to be invoked on-demand:

function bootstrap() {
    source "some-library.sh"
}

Minimally this should work for scripts ran by one specific user, but would prefer a solution that also extends to scripts executed by root.

So far I've tried /etc/profile & /etc/bash.bashr but no joy.

both /etc/{profile,bash.bashrc} had something similar:

_inittest_first() {
    echo this is imported from /etc/profile;
}
export -f _inittest_first

I presume export is not working due to dash being involved somewhere inbetween, as explained here

3
  • For your user or all users of the machine? And on what operating system? Commented Sep 22, 2020 at 11:01
  • Mainly for one user, but ideally scripts executed by root would also be able to invoke it. OS is debian. Commented Sep 22, 2020 at 11:13
  • 1
    Please show us what you added to /etc/profile and tell us how you tested it. Did you export the function? Commented Sep 22, 2020 at 11:19

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.