Guest User

Untitled

a guest
Jan 22nd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. function cfg.parser ()
  2. {
  3. IFS=$’\n’ && ini=( $(<$1) ) # convert to line-array
  4. ini=( ${ini[*]//;*/} ) # remove comments ‘;’
  5. ini=( ${ini[*]//\#*/} ) # remove comments ‘#’
  6. ini=( ${ini[*]/\ =\ /=} ) # remove anything with a space around ‘ = ‘
  7. ini=( ${ini[*]/#[/\}$'\n'cfg.section.} ) # set section prefix
  8. ini=( ${ini[*]/%]/ \(} ) # convert text2function (1)
  9. ini=( ${ini[*]/=/=\( } ) # convert item to array
  10. ini=( ${ini[*]/%/ \)} ) # close array parenthesis
  11. ini=( ${ini[*]/%\( \)/\(\) \{} ) # convert text2function (2)
  12. ini=( ${ini[*]/%\} \)/\}} ) # remove extra parenthesis
  13. ini=( ${ini[*]/#\ */} ) # remove blank lines
  14. ini=( ${ini[*]/#\ */} ) # remove blank lines with tabs
  15. ini[0]=” # remove first element
  16. ini[${#ini[*]} + 1]=’}’ # add the last brace
  17. #printf “%s\n” ${ini[*]}
  18. eval “$(echo “${ini[*]}”)” # eval the result
  19. }
Add Comment
Please, Sign In to add comment