SHTK_CONFIG_RUN_HOOK(3)
SHTK_CONFIG_RUN_HOOK(3) Library Functions Manual SHTK_CONFIG_RUN_HOOK(3)

shtk_config_run_hookExecutes a hook defined in a configuration file

shtk_import config

shtk_config_run_hook hook [arg1 .. argN]

The shtk_config_run_hook function executes the function hook, defined by the configuration file, in the same context as the file. Any arguments arg1 to argN are passed literally to the hook. Hooks should not be executed directly because otherwise they would need to use the shtk_config_get(3) familiy of functions to read the variables defined in the file, which could be quite strange.

Keep in mind that the hook will only be able to access the configuration variables previously registered with shtk_config_init(3). Any other variables will be hidden and not available to the hook.

Consider the following configuration file:

SRCDIR=/usr/src

show_srcdir_hook() {
    # Note that we can access SRCDIR directly, as would be normal in a
    # configuration file.  No need to use shtk_config_get.
    echo "SRCDIR is ${SRCDIR}"
}

Then, we could process the file and execute the defined hook like this:

shtk_config_init SRCDIR
shtk_config_load ".../path/to/the/file/above.conf"

# This will print nothing because SRCDIR is not available here.
echo "SRCDIR is ${SRCDIR}"

# But this will display the right SRCDIR value.
shtk_config_run_hook show_srcdir_hook

Errors during the execution of the hook result in the termination of the script.

shtk(3), shtk_config(3)

shtk_config_run_hook first appeared in shtk 1.1.

November 6, 2014 Debian