When I write, for example, (format "The value is %d." fill-column) and type C-c p after it, it outputs a result.

How could I do the same with a shell command? That is, to run a shell command within a emacs buffer in org-mode and insert the result in the same buffer?

  • 1
    (insert (shell-command-to-string "date")) and (insert (format "The value is %d." fill-column)) There may be other shell-command-to-string threads, so this question may end up being marked duplicate?
    – lawlist
    May 26, 2016 at 16:49
  • 1
    C-c p is an end-user reserved key binding (as are all C-c <letter> sequences). If if does anything, it should be because you yourself bound it to a command. Not telling us what that command is means we don't know for certain what you're describing.
    – phils
    May 27, 2016 at 2:00

1 Answer 1


Interactively, C-u M-! (i.e., shell-command with the universal argument prefix) will prompt you for a shell command and insert the output in the current buffer.

To do this from elisp code, see the comment from @lawlist

org-mode also has fairly sophisticated methods of its own for evaluating code, including both inline code and code blocks. First, you need to activate the languages you wish to use by setting the variable org-babel-load-languages. For bash scripts, you need to activate the language sh. After that, you can refer to bash code inline, as src_sh{<your code>}, or in separate code blocks:

#+BEGIN_SRC bash
<your code here>

You can then have the results of evaluating the code by typing C-c C-c while point is in the block. The result looks like this:

Here's an inline call to ~pwd~: src_sh{pwd} {{{results(=/home/tws/scratch=)}}}

And here's a short bash script as a code block:

#+BEGIN_SRC bash

| clean-defun.el |
| find           |
| helm-test.el   |
| helm-test.el~  |
| #tmp.org#      |
| tmp.org        |
| tmp.org~       |
| tmp.pwd        |
| tmp.R          |
| tmp.R~         |
| tmp.txt        |
| tmp.txt~       |

See its manual (org) Evaluating code blocks for more details.

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.