简体   繁体   English

在组织模式下从另一个会话获取变量的值

[英]Get value of a variable from another session in org-mode

How to share variables' values in org-mode between different sessions?如何在不同会话之间以组织模式共享变量的值?

Simple example: in session one I create _gpg_tmpdir简单示例:在会话一中,我创建了_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.问题是在组织模式下,在不同的代码会话(可能使用不同的代码语言)之间共享变量的最不痛苦的方式是什么。

You can use the name of the codeblock to reference its output from a different codeblock using the "var" attribute.您可以使用代码块的名称从使用“var”属性的不同代码块引用其输出。 For more info you can check in the orgmode documentation .有关更多信息,您可以查看 orgmode 文档

The first block needs to output the value:第一个块需要输出值:

#+name: make_temporary_directories
#+BEGIN_SRC bash :session *one* :results output
variable=`ls`
echo $variable
#+END_SRC

#+RESULTS: make_temporary_directories
: 
: file1 file2 file3 file4 file5 file6 file7 file8

The second block can refer to that value using the name of the previous codeblock:第二个块可以使用前一个代码块的名称引用该值:

#+BEGIN_SRC bash :session *two* :results output :var ls_result=make_temporary_directories
echo $ls_result
#+END_SRC

#+RESULTS:
#+begin_example

bash-5.0$ file1 file2 file3 file4 file5 file6 file7 file8
#+end_example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM