1

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?

2
  • 2
    export $GIT_PASSWORD If the password is ABC, then this becomes export ABC Commented Aug 1, 2022 at 15:13
  • export GIT_PASSWORD Commented Aug 1, 2022 at 15:50

3 Answers 3

5

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

export GIT_PASSWORD=$GIT_PASSWORD
Sign up to request clarification or add additional context in comments.

Comments

0
#!/bin/bash
while getopts 1: flag
do
        case "${flag}" in
                1) GIT_PASS=${OPTARG};;
        esac
done

export GIT_PASSWORD=$GIT_PASS

python - << EOF

import os

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

echo $GIT_PASSWORD

echo "Back to bash"

Comments

0

There's no real reason to use an environment variable at all; a simply command line argument would suffice.

GIT_PASSWORD=$1

python - "$GIT_PASSWORD" << EOF 
import sys
print(sys.argv[1])                                               
EOF

echo "Back to bash"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.