From d78ee7fedb0cf7b5d582e69370b974a4294ca022 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 13 Jan 2021 14:38:11 +0100 Subject: [ini] New module --- modules/ini.inc | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 modules/ini.inc diff --git a/modules/ini.inc b/modules/ini.inc new file mode 100644 index 0000000..c4a098c --- /dev/null +++ b/modules/ini.inc @@ -0,0 +1,11 @@ +# Get specific value from ini file +# ini_get
+ini_get () { + awk -v section="^\\\\s*\\\\[$2\\\\]" -v key="^\\\\s*$3\\\\s*=\\\\s*" '{if ($0 ~ section) {ins=1} else if ($0 ~ "^\\s*\\[") {ins=0} else if (ins && $0 ~ key) {gsub(key, ""); print; exit 0} }' "$1" +} + +# List all sections in ini file +# ini_sections +ini_sections () { + awk '{if (match($0, "^\\s*\\[([^\\]]*)\\]", a)) {print a[1]}}' "$1" +} -- cgit v1.2.3-55-g7522