Read Bash variables into a Python script

后端 未结 3 1114
攒了一身酷
攒了一身酷 2021-01-31 07:37

I am running a bash script (test.sh) and it loads in environment variables (from env.sh). That works fine, but I am trying to see python can just load in the variables already i

3条回答
  •  Happy的楠姐
    2021-01-31 08:24

    You need to export the variables in bash, or they will be local to bash:

    export test1
    

    Then, in python

    import os
    print os.environ["test1"]
    

提交回复
热议问题