I need to make an export like this in Python :
# export MY_DATA=\"my_export\"
I\'ve tried to do :
# -*- python-mode -*-
# -
I have an excellent answer.
#! /bin/bash
output=$(git diff origin/master..origin/develop | \
python -c '
# DO YOUR HACKING
variable1_to_be_exported="Yo Yo"
variable2_to_be_exported="Honey Singh"
… so on
magic=""
magic+="export onShell-var1=\""+str(variable1_to_be_exported)+"\"\n"
magic+="export onShell-var2=\""+str(variable2_to_be_exported)+"\""
print magic
'
)
eval "$output"
echo "$onShell-var1" // Output will be Yo Yo
echo "$onShell-var2" // Output will be Honey Singh
Mr Alex Tingle is correct about those processes and sub-process stuffs
How it can be achieved is like the above I have mentioned. Key Concept is :
printed
from python will be stored in the variable in the catching variable in bash
[output
]eval
print
output from python in a meaningful bash
commandseval
to execute it in bashAnd you can see your results
NOTE
Always execute the eval
using double quotes
or else bash
will mess up your \n
s and outputs will be strange
PS: I don't like bash but your have to use it