Skip to content

Instantly share code, notes, and snippets.

@sulincix
Created December 21, 2024 19:06
Show Gist options
  • Save sulincix/a7a97a899ec45db6b303518f34017838 to your computer and use it in GitHub Desktop.
Save sulincix/a7a97a899ec45db6b303518f34017838 to your computer and use it in GitHub Desktop.
posix shell ini parser without command
#!/bin/sh
parse(){
section="$1"
value="$2"
found="false"
while read line ; do
case $line in
[*)
if [ "$line" == "[$section]" ] ; then
found="true"
fi
;;
"$value"=*)
if [ "$found" == "true" ] ; then
ret=${line#*=}
echo $(eval echo $ret)
return
fi
esac
done < /dev/stdin
}
test(){
echo "[main]"
echo "name=\"main\""
echo "number=31"
echo "[test]"
echo "name=\"test\""
echo "number=13"
}
parse "main" "name" < <(test)
parse "main" "number" < <(test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment