be2edd19d8
fixed dir2subv functions add subv_snap fixed is_subv
16 lines
No EOL
454 B
Bash
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 "$@")
|
|
} |