Is there a way to execute a whole buffer's worth of code blocks, in an org file, and save them all in that org file, headlessly, from the command line?

Here's what I've tried so far, but it's not working (just hangs):

emacsclient -a --eval '(find-file "index.org")(org-babel-execute-buffer)(save-buffer)'

I'm also trying this:

#!/usr/bin/env bash
# Update Org-Babel files
emacsclient -a --batch --eval "
      (require 'ob-core)
      (dolist (file command-line-args-left)
        (with-current-buffer (find-file-noselect file)
  " "$@"

But this just returns nil and symbol is void...

1 Answer 1


Try this:

#! /bin/bash
# Update Org-Babel files
emacs --batch -l ob -l ob-shell --eval "
(let ((org-confirm-babel-evaluate nil))
      (dolist (file command-line-args-left)
        (with-current-buffer (find-file-noselect file)
  " $*

Depending on what language(s) your source blocks use, you might have to load additional languages.

You can't use --batch or -l with emacsclient - see its man page.

  • I'm getting No org-babel-execute function for sh!.
    – Jonathan
    Mar 8, 2022 at 22:27
  • You will need to load all the languages you use or else initialize org-babel-load-languages, e.g ...-l ob -l ob-shell -l ob-python -l ob-org .... The only one that's enabled by default is emacs-lisp AFAICT.
    – NickD
    Mar 8, 2022 at 22:32

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.