0

In Org Babel, in a bash code block, it seems impossible to get both :results header arg with both raw and replace. Is that expected?

The docs for shell Babel seem to suggest the only options for :results are file, list, and table. It seems weird that there is no way to just show the string sent to stdout by the shell code.

raw seems to work as an argument, but it makes replace not work. For instance in

#+begin_src bash :results raw replace
  tree .
#+end_src

where both list and table garble the result.

6
  • 1
    While I was testing, I found that just :results output seems to do the job. The docs mention that output is the default, however that info seems wrong, as it looks like output list is the actual default . Feb 12 at 17:59
  • Anything except raw does the job, in the sense that replace (which is the default) can figure out where the results end so that they can be cleared before the new results are inserted. raw just does not provide any markers to allow replace to do that. I've recommended drawer in the past instead of raw. @dalanicolai: output is a different kettle of fish - it's independent of the format (I can have :results output raw or :results output drawer e.g.); what it contrasts with is :results value. output is the default for many languages but not all (e.g. for elisp ...)
    – NickD
    Feb 12 at 21:57
  • ... (e.g. for elisp the default is value - in fact there are various claims that value is the default for most languages, but I prefer to set it explicitly when I don't know for sure). Most of these things are described in Results of Evaluation but the default value for the Collection has to be dug up from the specific language doc (or maybe its implementation - not every language is documented).
    – NickD
    Feb 12 at 22:07
  • @NickD I am largely aware of most points you mention here, but indeed I did not really think about how things should behave (the 'solution' simply worked). The situation is that for bash blocks, the output often automatically gets formatted as a list, like for the tree . output (I realize now, that this is just 'normal' org behavior, also without the list output value). For some reason, :results output prevents the output from getting formatted as a list. I now realize that this should not make a difference (AFAIK) but it does, as it makes the output to get wrapped as an example block. Feb 13 at 0:01
  • 1
    as it makes the output to get wrapped as an example block : that is standard behavior for output that is longer than 10 lines (configurable through org-babel-min-lines-for-block-output). Try tree . | sed 5q.
    – NickD
    Feb 13 at 1:57

1 Answer 1

2

Try drawer instead of raw:

#+begin_src shell :results drawer replace
tree .
#+end_src

raw does not provide any markers, so replace cannot figure out where the results end: you just get the new results prepended to the old results. drawer encloses the raw results in a drawer, enabling replace to figure out where the results end, so it can clear the old results before inserting the new ones.

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.