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 √ ~ % 
7
  • 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. Commented Jul 5, 2023 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. Commented Jul 5, 2023 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). Commented Jul 5, 2023 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. Commented Jul 5, 2023 at 23:21
  • 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. Commented Jul 6, 2023 at 5:31

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.