0

I have an input file that looks like:

VAR1=1
VAR2=2 
VAR3=3
VAR4=.T.

I'd like to read in these variables and define them as such. I've tried

 while read line
 do
  exec $line
 done < "Master.inp"

i've tried just

$line

instead, but that didn't work either. Is there a way to run the string as if I had just typed out the string in the bash file?

1 Answer 1

3

You can do it just sourcing the code:

. file

this will let you use the vars $VAR1, $VAR2, ...

Test

$ cat a
VAR1=1
VAR2=2
VAR3=3
VAR4=.T.

$ cat b
. a

echo $VAR1
$ ./b
1
Sign up to request clarification or add additional context in comments.

1 Comment

Excellent. I love it when the solution is simpler than I expected.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.