I am using Emacs version 26.3 and Org Mode version 9.3.6.

My goal is to have several different #+CALL: lines, each using a different value of some header argument (in the example below, that is inarg).

Typing C-c C-c on the first #+CALL: line below:

#+NAME: sub_func1
#+BEGIN_SRC bash :results verbatim :var inarg=""
echo sub_func1 inarg $inarg

#+NAME: main_func1
#+BEGIN_SRC bash :results verbatim :var inarg="" :var sub_func1_result=sub_func1(inarg=inarg)
echo main_func1 inarg $inarg sub_func1_result $sub_func1_result

#+CALL: main_func1(inarg="hardcoded1")
#+CALL: main_func1(inarg="hardcoded2")

produces this error:

org-babel-ref-resolve: Reference ‘inarg’ not found in this buffer

How do I pass the inarg variable all the way down to sub_func1 without having to hardcode the value of it in both main_func1 and sub_func1?

The results I expect are from the following, which I do NOT want to have to do as it means I have to update both values of "hardcoded1" when that value changes:

#+NAME: sub_func2
#+BEGIN_SRC bash :results verbatim :var inarg=""
echo sub_func2 inarg $inarg

#+NAME: main_func2
#+BEGIN_SRC bash :results verbatim :var inarg="hardcoded2" :var sub_func2_result=sub_func2(inarg="hardcoded2")
echo main_func2 inarg $inarg sub_func2_result $sub_func2_result

#+CALL: main_func2()

: main_func2 inarg hardcoded2 sub_func2_result sub_func2 inarg hardcoded2

1 Answer 1


You can "run an interactive session as an 'inferior process' within Emacs" using session-based evaluation, and reuse data objects between sharing-session blocks. Here's an example:

#+begin_src sh :session example

#+name: main_func1
#+begin_src sh :results verbatim :session example
echo $inarg

#+results: main_func1
: foo

#+CALL: main_func1(inarg="bar")

: bar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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