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>
#+END_SRC
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
ls
#+END_SRC
#+RESULTS:
| 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.
(insert (shell-command-to-string "date"))
and(insert (format "The value is %d." fill-column))
There may be othershell-command-to-string
threads, so this question may end up being marked duplicate? – lawlist May 26 '16 at 16:49C-c p
is an end-user reserved key binding (as are allC-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 '16 at 2:00