要求
(.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
问题
(.venv) Revanths-MBP:Home revanth$ echo $STAGE_VAR
(.venv) Revanths-MBP:Home revanth$
这不会打印任何内容,因为在上面的python进程中设置的环境变量不会被带到其父进程
另一种解决方案可能是这样的set_env_vars.py
会将所有env变量作为字符串返回,如下所示
export STAGE_VAR_1="stage_var_1"
export STAGE_VAR_2="stage_var_2"
...
...
...
export STAGE_VAR_N="stage_var_n"
现在是否可以管道(|)此输出并使用一些shell命令将上述输出作为输入并执行上面的每一行?