1

How to share variables' values in org-mode between different sessions?

Simple example: in session one I create _gpg_tmpdir

#+name: make_temporary_directories
#+begin_src bash :session *one*
_gpg_tmpdir="$( mktemp -d )"
#+end_src

and need to clean up it in session two:

#+name: clean_temporary_directories
#+begin_src bash :session *two*
rm -rf $_gpg_tmpdir
#+end_src

The example is for the demonstration purpose only. The question is what is the less painfull way to share variables between different code sessions (perhaps with different code languages) in org-mode.

  • Is this an XY problem? en.wikipedia.org/wiki/XY_problem Maybe clarify why you want to do this. The entire point of sessions is to keep things separate. If you must communicate between the two, this may not be an Org question but a general how do I share data between bash processes question. – mankoff Feb 12 at 22:55
  • You are right. I share data between bash sessions with something like set > .state-0000 and source .state-0000. It works but I don't like it. – trupanka Feb 12 at 23:23
  • Many systems use something like that. State files, when filed correctly are fine. It's no worse than anything else. Everything is a file... – RichieHH Feb 13 at 13:40
3

You can use RESULTS for the first session to write out the results, and :var in the second session to import results.

#+name: make_temporary_directories
#+begin_src bash :session *one* :results output
_gpg_tmpdir="$( mktemp -d )"
echo $_gpg_tmpdir
#+end_src
#+RESULTS: make_temporary_directories
: /tmp/tmp.iAE5oSlwcC
#+name: clean_temporary_directories
#+begin_src bash :session *two* :var gpg_tmpdir=make_temporary_directories :results output
echo $gpg_tmpdir
#+end_src
| improve this answer | |
  • Ok. The next question is: how to share results of one bash script in another? I want to tangle different logical sessions to different scripts. – trupanka Feb 13 at 8:10
  • ... and how to get rid of PS1 in results (I don't know why I get it): : trupanka@loststation ~/CLASSES/_PLAYGROUND/BASH $ /tmp/tmp.7QMo1uK8Up – trupanka Feb 13 at 8:14
  • ask your next question as a new question, the short answer is to use the :tangle header arg to send different babel blocks to different files. – mankoff Feb 13 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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