I have a shell script like below. If I have a test.py that has a variable a=5, how can I import the variable to the following shell script?

python test.py
b=10

if [ $a == $b ]
then
   echo "a is equal to b"
else
   echo "a is not equal to b"
fi
share|improve this question
    
using [ $a == $b ] is going to give you trouble you should use [[ $a == $b ]] or [ "$a" == "$b" ] and then only if $a or $b are strings. – the_velour_fog Oct 17 '16 at 7:43

You can return a variable from your python script. Put at your python script:

a="something"
print(a)

And at your shell script:

a=$(python script.py)
b="something"

if [ "$a" == "$b" ]; then
... 
... 
... 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.