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 ??
Asked
Active
Viewed 109 times
0
-
I could write the variable to a temp file but I want to know if there is any way to send the data back to the shell parent without involving filesystem. – user1600936 Oct 24 '13 at 07:54
1 Answers
2
variable=$(python - <<EOS
...
EOS
)
Whatever the python script writes to stdout will be stored in the variable.

Barmar
- 741,623
- 53
- 500
- 612
-
But This will dump everything the snippet writes, What do I do if I want to selectively send something ? – user1600936 Oct 24 '13 at 08:13
-
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. – Barmar Oct 24 '13 at 08:45
-
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 Oct 24 '13 at 09:03
-
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. – user1600936 Oct 24 '13 at 09:52