0

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
  • 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. Commented Oct 24, 2013 at 7:54

1 Answer 1

2
variable=$(python - <<EOS
...
EOS
)

Whatever the python script writes to stdout will be stored in the variable.

Sign up to request clarification or add additional context in comments.

4 Comments

But This will dump everything the snippet writes, What do I do if I want to selectively send something ?
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.
I guess using posix IPC would be a way, but that would make the code too complicated. I just want something fast and easy.
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.

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.