shell-base/modules/scripting/ini.mod
David Kebler be2edd19d8 added functions for ini file parsing and conversion to environment vars
fixed dir2subv functions
add subv_snap
fixed is_subv
2025-01-02 17:23:00 -08:00

16 lines
No EOL
454 B
Bash

#!/bin/bash
# https://stackoverflow.com/a/61329094
parse_ini () {
local ini=$1
if [[ ! -f $ini ]]; then ini=$1.ini; if [[ ! -f $ini ]]; then echo no file "$ini"; return 1; fi fi
sed -n -E "/^\[.*\]/{s/\[(.*)\]/\1/;h;n;};/^[a-zA-Z]/{s/#.*//;G;s/([^ ]*) *= *(.*)\n(.*)/\3_\1='\2'/;p;}" "$ini" | \
sed -E 's/^_//'| \
sed -E 's/^([^=]*)[.]/\1_/' | \
sed -E 's/^([^=]*)[-]/\1_/' | \
( [[ $2 ]] && grep "$2" || cat )
}
ini2env () {
eval $(parse_ini "$@")
}