-2

I found this bash script here on stackoverflow that parses an ini file with bash, and it works great. But I'd like to convert this to ksh but get this message when running it with ksh...

ini_test02.ksh[24]: eval: syntax error at line 7: `end of file' unexpected

ini_test02.ksh[51]: cfg.section.DEFAULT: not found [No such file or directory]

How can you convert this into a ksh script?

Community
  • 1
  • 1
  • You can refer to the [Ksh manual](http://www2.research.att.com/sw/download/man/man1/ksh.html). Please post what you have tried. – konsolebox Jul 13 '14 at 15:33
  • Not sure on where to begin... Just tried to invoke the script/function using ksh and this is what was returned. Perhaps it's eval and not ksh or is it that function_name.section.section_name is being interpreted by bash as just a function name and ksh is using its object-oriented feature when running the function? – Carl Lindgren Jul 13 '14 at 16:00
  • I've changed the set to >> ini=( ${ini[*]/#\\[/\}$'\n'cfg_section_} ) using underscores instead of periods and get the same results. – Carl Lindgren Jul 13 '14 at 16:54
  • It's atually difficult to convert the function. When run in bash the function creates a function with a name that's not compatible with ksh. e.g. `cfg.section.parameters.ini () { database_user=( user ) database_version=( 20110611142248 ) } `. I'm not sure how it would really work with ksh and how you could make use of it. – konsolebox Jul 15 '14 at 13:44

2 Answers2

0

If you do not have a lot of vars, just parse them one by one. When the values do not contain an equal sign the following might do:

keyx="$(grep "^keyx=" my.ini | cut -d= -f2 | sed 's/ *$//')"

Or put this in a function and call the function like

keyx="$(readini my.ini keyx)"
Walter A
  • 19,067
  • 2
  • 23
  • 43
0

Since this is one of the top search results on google with ksh and INI parsing I'd like to point to https://github.com/wallyhall/shini for INI parsing in KSH.

The only thing that needs to be done is to implement the function(s) __shini_parsed and optional __shini_parsed_section.

Benjamin
  • 155
  • 6