6

I would like to build a shell command using elisp and then printing the result so it is stored in a #+RESULTS block and from there execute that result block as a shell command still inside the org-mode document.

How do I achieve that?

1
11

Maybe the header argument :wrap can help, e.g.,

#+BEGIN_SRC elisp :wrap src sh
(format "echo %s" (shell-quote-argument user-full-name))
#+END_SRC

#+RESULTS:
#+BEGIN_src sh
echo Xu\ Chunyang
#+END_src

#+RESULTS:
: Xu Chunyang
1
  • 1
    I often use the :wrap "src json" option for a org mode source block, when the output is JSON. Jul 23 '19 at 7:32
0

I give you an example org-file below. The emacs-lisp source block on top prints the shell source block inclusive the limiters #+begin_src sh and #+end_src.

The result format of the emacs-lisp source block is raw. That way the generated shell source block is directly embedded into the org file.

If you evaluate the org buffer with M-x org-babel-execute-buffer the Elisp source block and the updated shell source block are executed.

#+begin_src emacs-lisp :results raw
(princ "#+begin_src sh
echo \"Hello World.\";\n#+end_src")
#+end_src

#+RESULTS:
#+begin_src sh
echo "Hello World.";
#+end_src

#+RESULTS:
: Hello World.

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.