I have a tiny project that configures and installs some shell scripts using GNU autotools.

Now, the scripts will have to source a common file containing some shell functions.

Where should this file be installed by make install?

According to "Variables for Installation Directories", libexecdir is for executable files (the file containing the shell functions is not an executable in itself) and datadir is for architecture-independent data (this file depends on the architecture).

Is there any precedent for using any of these two paths (or any other installation path) for installing a file containing only shell functions? These functions are not meant to be used separately at the moment.

  • /usr/local/share or /usr/share? Feb 26 '17 at 10:23
  • 1
    If you don't like libexec my second guess would be /usr/local/lib/your_app. After all it's a library, albeit one of shell functions. Feb 26 '17 at 11:26
  • 1
    While I can’t answer your second question, the answer to your first question is that it’s up to you. If following FHS/GNU standards is important to you, just decide for yourself whether shell functions seem more like data to you, or more like executable programs to be run by other programs. That said, I personally prefer to view them as code; in many ways, the interpreter executes a function just like it would run a standalone script – even though the invocation ritual and other details differ. Due to that, I use pkglibexecdir (or libexecdir if I want other packages to use them, too).
    – Synoli
    Apr 20 '18 at 6:50

Your functions to be installed are in the context of your shell.
So store them there: ~/.bash_functions

Every time your shell loads, it loads commands, ~/.bashrc, and even aliases, ~/.bash_aliases. These are shell scripts which simply add commands to the shell PATH variable or set aliases. Shell scripts which define functions, to follow suit, should be defined here as well.

Then append a line to your .profile or .bashrc to ensure they are loaded for your terminal or just at the beginning of your shell scripts which depend on them:

if [ -f ~/.bash_functions ]; then
    . ~/.bash_functions

Append functions to the file as desired:

# ~/.bash_functions file
function_one () {
    echo "hi"
function_two() {
  • The scripts are potentially to be installed system-wide, the functions are to be loaded from the script, and the functions are not for interactive use. Also, I don't use bash.
    – Kusalananda
    Jun 14 '18 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.