Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Shell – Pass env variable to Python Script

I have the shell script where I create a Python file on the fly:

#!/bin/bash

args=("$@")

GIT_PASSWORD=${args[0]}
export $GIT_PASSWORD

python - << EOF

import os

print(os.environ.get("GIT_PASSWORD"))
                                                         
EOF

echo $GIT_PASSWORD

echo "Back to bash"

I want to be able to access the variable GIT_PASSWORD, but unfortunately, I am not able to pass it to the python file.

Does anyone know what I am doing wrong and how I may fix that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The thing is that you’re not actually setting an env variable, you need to change the export:

export GIT_PASSWORD=$GIT_PASSWORD
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading