0

Given a config file, IterVars.txt, of the following format, I need to create a script that will call three of the variables listed.

[itervars]
idx1 = 13.0
trigger1 = True
trigger2 = False
startres = 0.123456789
endres = 0.000000123

I've tried several key value variable assignment explanations I found here, but it seems all of them have an issue with the spaces in the file, in that it interprets text after the space as a new command. How do I call these variables in a shell script as:

$idx1=13.0
$trigger1=True
$trigger2=False
codeforester
  • 39,467
  • 16
  • 112
  • 140
  • 1
    Possible duplicate of [How do I grab an INI value within a shell script?](https://stackoverflow.com/questions/6318809/how-do-i-grab-an-ini-value-within-a-shell-script) – wjandrea Dec 21 '19 at 19:15
  • Since the config file is short and you only need three values, it's probably easiest to use the AWK solution [in this answer](https://stackoverflow.com/a/6318837/4518341). You could functionalize it to reduce code duplication. – wjandrea Dec 21 '19 at 19:17

1 Answers1

1

You your case and because of the space symbols you can try something like:

source <(grep = IterVars.txt|sed -E $'s/[ \t]*=[ \t]*/=/')

in your script and you will have variables defined in to the script

Romeo Ninov
  • 6,538
  • 1
  • 22
  • 31