Library
noun
say it: “LY-brer-ee” /ˈlaɪbrɛri/
A file of functions that several scripts share by loading it, so a fix made in the file reaches every script that uses it.
What is a library in a bash script?
A library is a file that holds functions and nothing else. Scripts load it with source, so they share one copy: fix a bug in the library and every script that loads it gets the fix. Nobody runs it on its own, so it needs no #! line and no chmod +x.
# mix-lib.sh holds the functions banner and sum_minutes
here=$(dirname "${BASH_SOURCE[0]}")
source "$here/mix-lib.sh"
echo "Total: $(sum_minutes 4 3 5) minutes" # Total: 12 minutes
In a sentence
- “Both playlist scripts load the same library, mix-lib.sh, for banner and sum_minutes.”
- “When Sam fixed sum_minutes in the library, mix.sh and stats.sh were both fixed at once.”
Level: Journeyman · More Unix terms at this level
Updated