2

Requirement

(.venv) Revanths-MBP:Home revanth$ python set_env_vars.py # this will get an environment variable from the server and has to set that environment variable

set_env_vars.py

def main():
    stage_vars = get_stage_vars(project_name, branch, aws_region)
    import os
    for key, value in stage_vars.items():
        os.environ[key] = value

Problem

(.venv) Revanths-MBP:Home revanth$ echo $STAGE_VAR

(.venv) Revanths-MBP:Home revanth$

This will not print anything because the environment variables set in the above python process are not carried to its parent process

Another solution could be something like this set_env_vars.py would return all the env variables as a string like below

export STAGE_VAR_1="stage_var_1"
export STAGE_VAR_2="stage_var_2"
...
...
...
export STAGE_VAR_N="stage_var_n"

Now is it possible to pipe(|) this output and use some shell commands to take the above output as input and execute each line above ?

Revanth Gopi
  • 350
  • 4
  • 14
  • Similar to: https://stackoverflow.com/questions/1279953/how-to-execute-the-output-of-a-command-within-the-current-shell maybe? – Maciek Jun 28 '17 at 13:52
  • yeah this question helped upto some extent but check this https://stackoverflow.com/questions/44823668/how-to-change-this-shell-script-to-a-single-command-using-the-source-command-to – Revanth Gopi Jun 29 '17 at 11:22

0 Answers0