0

I'm trying to write some shell code blocks in a session, but it seems no session has been started, and all the code blocks are run independently. Here is a simple example:

* org-babel
:PROPERTIES:
:header-args:shell :session babel
:END:

#+begin_src sh
pwd
#+end_src

#+RESULTS:
: /Users/olivier/git/mybrain


#+begin_src sh
cd ..
pwd
#+end_src

#+RESULTS:
: /Users/olivier/git

#+begin_src sh
pwd
#+end_src

#+RESULTS:
: /Users/olivier/git/mybrain

As can be see from above, I changed the working directory to the parent folder in the second block, but it went back to the original folder in the next block.

But I do know the session is not working, because there is a background buffer babel opened in the background, but it's an empty buffer with :no process written at the bottom.

Can someone tell me what's going on and how to fix this?

0
2

Two things:

  1. the language name here is sh, not shell
  2. the colon is missing after the language name

The following works:

* org-babel
:PROPERTIES:
:header-args:sh: :session babel
:END:

#+begin_src sh
pwd
#+end_src

#+RESULTS:
: /Users/olivier/git/mybrain

#+begin_src sh
cd ..
pwd
#+end_src

#+RESULTS:
: /Users/olivier/git

#+begin_src sh
pwd
#+end_src

#+RESULTS:
: /Users/olivier/git
6
  • Agree with 1. and 2. but not with 3. - the name of the session can (within reason) be anything one wishes. Try with foo-bar-baz* e.g.
    – NickD
    Nov 6 '21 at 17:35
  • @NickD Indeed, thanks!
    – JeanPierre
    Nov 6 '21 at 17:55
  • Thanks @JeanPierre and @NickD! I was under the impression that sh is just an alias for shell, but apparently it's not so.
    – Olivier Ma
    Nov 7 '21 at 6:33
  • Indeed it is, as is every other name in org-babel-shell-names, but you have to be consistent:if you decide to use, say, bash for the name of the language of the source blocks, you got to use the sane name in the :header-args:bash spec e.g. Babel just matches the string to figure out whether the header arg applies to a given source block.
    – NickD
    Nov 7 '21 at 13:44
  • Also, you should probably use C-c C-x p to add the property :header-args:shell - that would take care of the missing colon in @JeanPierre's point 2. Note that that colon is part of the property syntax, not part of the header arg spec, which is just :header-args:shell.
    – NickD
    Nov 7 '21 at 13:48

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.