Bash: where to put and how to load function libs?
I'm in the process of reorganizing bash/shell scripts I've accumulated
over the years. In several places I have been lazy and as a result there
is duplicate code that I want to extract into shared function libraries.
This has led me to a few questions:
Where do I put shell function libs? There are several candidates:
- /usr/local/share: they are architecture independent, after all
- /usr/local/lib: that's where pythonX.Y and site_ruby go
What's the proper extension?
- .sh: even if it's bash code?
- .bash.
- .functions
How do I test a script that's sourcing such a lib *without* installing
the lib?
# my-script:
#!/bin/bash
. /usr/local/lib/my.functions
...
The file at /usr/local/lib/my.functions is the current "production"
version. However, I want to test the version at
/usr/local/src/myscripts/my.functions. I'm considering something like
this
# my-script:
#!/bin/bash
. ${SCRIPT_LIB_PATH:-/usr/local/lib}/my.functions
$ SCRIPT_LIB_PATH=/usr/local/src/myscripts my-script
Is there a better way?
Michael
--
Michael Schuerig
mailto:michael@schuerig.de
http://www.schuerig.de/michael/
Reply to: