0

I have a file with content:

EnableSchemaValidation="False"
EnableRedshiftImport="True"

how do I run a bash/shell command to parse this file and set environment variables as:

√ ~ % echo ${EnableSchemaValidation}
False
√ ~ % echo ${EnableRedshiftImport}
True
√ ~ %
Biao Yu
  • 11
  • 3
  • 2
    `source myEnvFile` ? You can do this on the cmd-line OR include it in a script just before you need your envVars, OR more commonly at/near the top of your script. With a script you may need to make the location/path of the file an envVar (as well) OR just hard-code it , i.e. `source /path/to/myEnvFile`. Good luck. – shellter Jul 05 '23 at 23:02
  • 1
    Per your topic message "read file, pass contents to env var", I had assumed you meant you needed `envVar=$(< /path/to/file_With_value_only_Contents)` . In your case where `/path/to/file...` has just the value `False`, you would do `EnableRedshiftImport=$(< /path/to/file...)`. Good luck. – shellter Jul 05 '23 at 23:08
  • 1
    Is the file's content _actually valid bash source_? (That's true for the lines you showed, but using `source` or equivalent requires that it be true universally, and risks security problems otherwise). – Charles Duffy Jul 05 '23 at 23:16
  • btw, saying you want to parse the file into "an" environment variable when you actually want a separate environment variable per line of the file is a bit misleading. – Charles Duffy Jul 05 '23 at 23:21
  • And if it's not in valid bash syntax, you need to define what its syntax is before this question can be answered. – Gordon Davisson Jul 05 '23 at 23:21
  • @shellter: For the example data, this would not make the variables **environment** variables. – user1934428 Jul 06 '23 at 05:29
  • 1
    You just gave an **example** of how this file could look like. You would have to specify in general the syntax of this file in order to get a reasonable answer. For the concrete example which you have posted, it would be sufficient to prepend each line of the file with `export ` and then source the file. – user1934428 Jul 06 '23 at 05:31

0 Answers0