如何在 org babel 中加载 bash(而不是 sh)以启用 #+BEGIN_SRC bash?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29163164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 12:34:45  来源:igfitidea点击:

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

bashorg-modeorg-babel

提问by mzimmermann

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

但是在我的组织模式版本(elpa,org 20150316)的菜单中customize-variable org-babel-load-languages,没有“bash”项,只有外壳。尝试评估代码,例如

#+BEGIN_SRC bash
ls -l
#+END_SRC

I get

我得到

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

org-babel-execute-src-block:bash 没有 org-babel-execute 函数!

What am I missing?

我错过了什么?

Thanks.

谢谢。

回答by Linus Arver

For me, I did

对我来说,我做到了

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

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

http://orgmode.org/elpa.html所示,以确保我拥有最新的 Org 版本(vanilla Emacs 附带了自己的 Org 版本)。然后我org在执行M-x list-packages. 那我可以做

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

which allows #+BEGIN_SRC bash.

这允许#+BEGIN_SRC bash.

回答by fniessen

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

查看的值org-babel-sh-command(默认为“sh”),并且只使用“sh”作为语言。

回答by Luke

It seems bashis covered by the shellidentifier.

它似乎bashshell标识符覆盖。

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

因此,您必须在customize-variable org-babel-load-languages.

Tested version: 20150810 from MELPA.

测试版本:来自 MELPA 的 20150810。