1

I have the following source block in my Org mode file:

#+begin_src sh :results output
  exec 2>&1
  mkdir -p /tmp/example && cd /tmp/example
  echo "hello" > world
  rg --color=never 'hello'
  :
#+end_src

However, I never see any output in Org mode. The same code works fine in my shell. I've also compared the environment of both the org-babel-execute:shell results and my shell and they seem to differ only in TERM.

Why doesn't rg output anything when I execute my block?

Zeta
  • 1,045
  • 9
  • 18
  • 1
    @Drew are you certain about that tag? – Zeta Apr 09 '21 at 06:19
  • Nope - rolled back. Thx. (The tag should get a proper description. And it looks like there are two very different `rg` meanings.) – Drew Apr 09 '21 at 17:38
  • 1
    @Drew [I'm on it](https://emacs.stackexchange.com/posts/64365/revisions) for `ripgrep`. The other [tag:rg] is used on `rg.el` which uses `ripgrep` behind the scenes, so [tag:rg] might still be fine, but [tag:ripgrep] is more explicit, see also [my synonym proposal](https://emacs.meta.stackexchange.com/questions/583/make-rg-a-synonym-of-ripgrep).. – Zeta Apr 09 '21 at 19:58

1 Answers1

4

This is likely related to this issue in ripgrep. As you didn't specify any file pattern, rg also reads from STDIN. For some reason, this yields to no result at all in your example, probably because Org uses your script as input into a shell (sh < your-sh-scode).

However, if you use /dev/null or an explicit file pattern as input for rg, it works fine:

#+begin_src sh :results output
  exec 2>&1
  mkdir -p /tmp/example && cd /tmp/example
  echo "hello" > world
  rg --color=never 'hello' </dev/null
  :
#+end_src
Zeta
  • 1,045
  • 9
  • 18