HomeSoftwareGamesMusicForum

Loading shell functions

Example: The following is an excerpt from my configuration files. Shell function made solely for bash reside in /local/shellfunc/bash, functions for ksh in /local/shellfunc/ksh, and functions for both in /local/shellfunc/bash+ksh. The configuration files look like this:
  • Kornshell: In the file ~/.profile
    export FPATH=/local/shellfunc/ksh:/local/shellfunc/bash+ksh
    PATH+=":$FPATH"
  • Bash: In te file .bash_login
    export FPATH=/local/shellfunc/bash:/local/shellfunc/bash+ksh
    PATH+=":$FPATH"
    source ~/.bashrc
    For the sake of simplicity, the file .bashrc, which gets sourced by interactive shells only, loads all of the functions:
    loadfunc -a
    As bash doesn't source this file automatically in login shells, .bash_login calls source ~/.bashrc explicitly. The file .bashrc contains additional settings needed by interactive shells, like option settings, prompt strings etc.
In contrast to ksh, bash allows automatic pre-loading of functions in scripts as well (though it is not recommended). To enable it, assign the path of the file containing the definitions to the exported variable BASH_ENV (in .bash_login). After this, bash will perform a source $BASH_ENV at every script start.
up
Created 2011-08-11 by mopcoge