How can I load bash (as opposed to sh) in org babel to enable #+BEGIN_SRC bash?
Asked Answered
N

4

30

I see references to, and examples that use

#+BEGIN_SRC bash

But in my org mode version (elpa, org 20150316) in the menu of customize-variable org-babel-load-languages, there is no "bash" item, only shell. Attempting to evaluate code such as

#+BEGIN_SRC bash
ls -l
#+END_SRC

I get

org-babel-execute-src-block: No org-babel-execute function for bash!

What am I missing?

Thanks.

Neman answered 20/3, 2015 at 9:21 Comment(4)
Just a thought, but could you try #+begin_src sh :shebang "#!/bin/bash"?Vacillation
This works for the example I gave, so I should accept it if you make your comment into answer. Although my original purpose was to use some of the ability to process associative arrays discussed here which the `:shebang' solution does not provide. I think all this points to the ob-sh.el , part of org on melpa, does not have some patches I expected.Neman
The problem is both melpa and elpa have an older version of ob-sh.el which does not have the bash changes. The version on [org git](git://orgmode.org/org-mode.git) does have a version ob-shell.el with bash enabled. Requiring/loading this version in my init.el, something like (load-file "~/org-git/org-mode/lisp/ob-shell.el") allows #+BEGIN_SRC bash and also allows org babel processing of associative arrays.Neman
Yes, ob-shell.el is the key.Enough
W
29

For me, I did

(require 'package)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)

as shown on http://orgmode.org/elpa.html to make sure I had the latest Org version (vanilla Emacs ships with its own version of Org). Then I installed the org package interactively after doing M-x list-packages. Then I could do

(org-babel-do-load-languages 'org-babel-load-languages
    '(
        (shell . t)
    )
)

which allows #+BEGIN_SRC bash.

Wooldridge answered 5/10, 2016 at 10:58 Comment(1)
In case it isn't obvious, one adds the org-babel-do-load-languages code snippet into your .emacs file.Faultless
I
6

It seems bash is covered by the shell identifier.

Therefore, you have to activate insert “Shell Script” in customize-variable org-babel-load-languages.

Tested version: 20150810 from MELPA.

Indeterminate answered 19/8, 2015 at 15:45 Comment(0)
S
5

See the value of org-babel-sh-command (which defaults to "sh"), and only use "sh" as the language.

Scolopendrid answered 20/3, 2015 at 12:40 Comment(8)
I already set to bash in my init.el. I think the problem is that the ob-sh.el, part of org on melpa (I am using melpa, not elpa as I stated) has no mention of bash. Perhaps that means it does not have some patches, I need to look into it further and maybe get a later version...Neman
After cheking, it seems the above var disappeared from Git Org. It seems to have been replaced by org-babel-shell-names. Maybe putting "bash" as the first component of it? ... if it does exist in your Org version?Scolopendrid
What version of org-babel are you using? The problem is even the most recent version on Melpa or Elpa does not even have org-babel-shell-names or any other bash processing. Not sure if it is licensing or omission. I am now using ob-shell.el from org Git repo rather then the ob-sh.el shipped on Elpa/Melpa and that provides all that I need. Still interesting why Elpa/Melpa is shipping an older version.Neman
I'm using Org-mode version 8.3beta (release_8.3beta-902-gac1298 @ /path/to/orgmode.git)!??Scolopendrid
See comments.gmane.org/gmane.emacs.orgmode/83356, particularly the comment of Eric Schulte (main author of Babel). I'm not sure I fully understand it, though.Scolopendrid
On versions: My version is Org-mode version 8.2.10 (8.2.10-35-g19a7d6-elpa ) which is the latest on Elpa. I like using packages from Elpa/Melpa for simplicity - which in this case clearly does not have the ob-shell.el but rather ob-sh.el that I suppose you have in your beta. The link you sent confirms my above comments where it talks about the rename from "sh" to "shell". I suppose will wait for Elpa to move to 8.3 version (although it all already works for me with the manually loaded ob-shell.el )Neman
Pay attention, though, when loading ob-shell: you end up mixing Org versions, what could lead to troubles. OTOH, if you don't see anything wrong, there's no reason not doing it...Scolopendrid
Yeah, everything behaves normal so far. But you are right , I agree, not recommending mixing versions. Looking for 8.3 to be out of beta. Thanks!Neman
S
2

if you are using straight/ use-package try this:-

(use-package ob-shell
  :straight nil
  :after org
  :config
  (setq org-babel-default-header-args:sh '((:results . "output")))
  (setq org-babel-default-header-args:shell '((:results . "output"))))
Soapwort answered 26/5, 2021 at 7:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.