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?

3
  • 1
    @Drew are you certain about that tag? – Zeta Apr 9 at 6: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 9 at 17:38
  • 1
    @Drew I'm on it for ripgrep. The other rg is used on rg.el which uses ripgrep behind the scenes, so rg might still be fine, but ripgrep is more explicit, see also my synonym proposal.. – Zeta Apr 9 at 19:58
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.