Created
January 29, 2012 00:06
-
-
Save ggtools/1696356 to your computer and use it in GitHub Desktop.
Parse .ini file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reads a section of the ini file and put the results in variables prefixed by the supplied prefix. | |
readIniSection() { | |
local PREFIX="$1" | |
local SECTION="${2-main}" | |
# Neat way to parse the ini section from CONFIG_FILE | |
# shamelessly taken from http://www.tuxz.net/blog/ | |
eval `sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \ | |
-e 's/;.*$//' \ | |
-e 's/[[:space:]]*$//' \ | |
-e 's/^[[:space:]]*//' \ | |
-e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \ | |
-e "s/^\(.*\)=/${PREFIX}\1=/" \ | |
< $CONFIG_FILE \ | |
| sed -n -e "/^\[$SECTION\]/,/^\s*\[/{/^[^;].*\=.*/p;}"` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment