I am running a python snippet inside a heredoc in bash script. I want to pass a string from a python variable to the shell. Perhaps set a shell variable. How can I do this ??
1 Answer
variable=$(python - <<EOS
...
EOS
)
Whatever the python script writes to stdout will be stored in the variable.
4 Comments
user1600936
But This will dump everything the snippet writes, What do I do if I want to selectively send something ?
Barmar
Other than writing to a file, I don't think there's a way. A process can't modify variables in another process directly. Either you use files or a pipe.
user1600936
I guess using posix IPC would be a way, but that would make the code too complicated. I just want something fast and easy.
user1600936
I've decided to implement the whole script functionality in python itself, with a minimal wrapper bash script. Anyway, thanks for your help. I really appreciate it.