Hi everyone,

Quick follow up about this: following Eric's suggestion, I came up with the following block, which cleans up all the cruft from the output of the =script= command and produces a nicely formatted session transcript:

#+NAME: cleanup
#+BEGIN_SRC emacs-lisp :var data="" :results value :exports none
  (replace-regexp-in-string
   "\\$ exit\\(.\\|\n\\)*$" ""
   (replace-regexp-in-string
    "^bash-.*\\$" "$"
    (replace-regexp-in-string
     "\\(\\(.\\|\n\\)*?\\)\\$\\(.\\|\n\\)*\\'" ""
     (replace-regexp-in-string "
" "" data) nil nil 1)))
#+END_SRC

(I am not happy with the regexp nesting and repetition above, I am not an expert yet in emacs-lisp regex facilities. Suggestions appreciated for how to simplify it).

This produces exactly the result I need:

#+begin_src sh :exports output :results output :wrap "src console" :post cleanup(data=*this*)
script <<EOF
echo hi
echo bye
EOF
#+end_src

#+RESULTS:
#+begin_src console
$ echo hi
hi
$ echo bye
bye
#+end_src

Thanks Eric!

--Diego


On Thu, Feb 6, 2020 at 9:45 PM Diego Zamboni <diego@zzamboni.org> wrote:
Hi Eric,

Great idea! I hadn't considered using the =script= command, it's a great starting point.

Thanks!
--Diego


On Thu, Feb 6, 2020 at 7:55 AM Fraga, Eric <e.fraga@ucl.ac.uk> wrote:
On Wednesday,  5 Feb 2020 at 18:25, Diego Zamboni wrote:
> tl;dr: is there a way to have ob-shell (or some similar mode) run commands
> one by one and include the commands, interspersed with their output, in the
> #+RESULTS block?

You haven't said on what type of system but, if Linux, you could try
using =script= as a starting point:

#+begin_src shell :results output
  script <<EOF
  ls
  echo 'hello'
  EOF
#+end_src

You may wish to have a second shell script that massages the output in
the =typescript= file and ouputs that instead, e.g. to filter the
carriage returns.
--
: Eric S Fraga via Emacs 28.0.50, Org release_9.3.2-233-gc2bc48