Closed sengaya closed 4 years ago
It should work using quotes.
getkeyfromsection.sh <file.ini> "sectionname with spaces" keyname
Unfortunately no: When I change the section in file.ini
to [sec1 with-space]
and run
bash -x ./getkeyfromsection.sh file.ini "sec1 with-space" var1
I can see:
[...]
+ eval '
cfg_section_sec1 with-space () {
cfg_unset ${FUNCNAME/#cfg_section_}
var1=( foo )
var2=( hoge )
var3=( fuga )
var4=( pivo )
}
[...]
and it fails with
../bash-ini-parser: eval: line 64: syntax error near unexpected token `('
../bash-ini-parser: eval: line 64: `cfg_section_sec1 with-space () {'
Fixed on d9dfb77
You should be able to read section/subsection with a _
:
So for:
file.ini
[profile user1]
region=us-east-1
output=text
You can query values as:
$ ./scripts/getkeyfromsection.sh file.ini profile_user1 region
show parsed file.ini
[profile_user1]
region="us-east-1"
output="text"
region value is "us-east-1"
There're new test on t0003-sections
for this subsection
Let me know if that works for you
Awesome, works as expected! Many thanks!
It would be nice if whitespaces in the section name could be supported as for example used here: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html
I think that either remove the whitespace or replace it with a defined character (e.g.
_
) could be a solution.