SHTK_CONFIG(3)
π NAME π
okay bestie, this is the SHTK_CONFIG(3) page from the Library Functions Manual β folded in right here at the top because we do not do boring header lines π
. The star of the show is config β Configuration file processing and queries. Periodt.
π¦ LIBRARY π¦
Import the module with:
shtk_import config
β¨ DESCRIPTION β¨
The config module gives you a mechanism to load configuration files and to handle any settings defined in them. No cap.
Configuration files are simply shell scripts that can define a set of predefined variables. That is literally the whole model, bestie. ππ
π EXAMPLES π
Consider the following configuration file:
MYVAR1="this is the first setting"
MYVAR2="this is the second setting"
post_load_hook() {
echo "Custom hook! The file has been loaded!"
}
The following sample code depicts a main method to load the file above, including support for specifying the path to the configuration file and support to accept command-line overrides to the configuration variables:
local config_file="/etc/foo.conf"
shtk_config_init MYVAR1 MYVAR2
local OPTIND
while getopts ':c:o:' arg "${@}"; do
case "${arg}" in
c) # Path to the configuration to load.
config_file="${OPTARG}"
;;
o) # Override for a particular configuration variable.
shtk_config_override "${OPTARG}"
;;
\?)
shtk_cli_usage_error "Unknown option -${OPTARG}"
;;
esac
done
shift $((${OPTIND} - 1))
shtk_config_set MYVAR1 "default value for first variable"
# No default value for MYVAR2
post_load_hook() { true; }
shtk_config_load "${config_file}"
echo "MYVAR1 is $(shtk_config_get MYVAR1)"
echo "MYVAR2 is $(shtk_config_get_default MYVAR2 "not yet set")"
shtk_config_run_hook post_load_hook
π₯ SEE ALSO π₯
go read these too, bestie, they are the whole friend group π«Ά
shtk(3)shtk_config_get(3)shtk_config_get_bool(3)shtk_config_get_default(3)shtk_config_has(3)shtk_config_include(3)shtk_config_init(3)shtk_config_load(3)shtk_config_override(3)shtk_config_run_hook(3)shtk_config_set(3)shtk_config_unset(3)
π HISTORY π
config first appeared in shtk 1.0. iconic origin story, honestly πβ¨
That is the tea π«π
β the source stamp is Debian, the page id is SHTK_CONFIG(3), and the date is November 6, 2014 πβ¨π¦
π¦ where this page comes from
- nixos 26.05: shtk 1.7
- nixpkgs unstable: shtk 1.7
- Copyright 2014 Google Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms