1

I don't know if the presence of a leading * was meant to be in the code or if it's just a typo, but still I didn't expect it would break the code as if interpreted as a headline. Has dis been documented somewhere?

** DONE Programming - Python
  [2022-06-26 Sun]
 
#+BEGIN_SRC sh
$ sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).

Selection    Path                       Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.8          2         auto mode
1            /usr/bin/python3.8          2         manual mode
2            /usr/local/bin/python3.10   1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 
#+END_SRC

enter image description here

2
  • Yeah it breaks... Not sure its intended/bug/... But I got it working by inserting a zero width space before the '*' ie Do C-x 8 RET ZERO WIDTH SPACE with point at *, which may cause other problems correctable by part of an answer to my recent question emacs.stackexchange.com/a/72520/5223 -- See my comments
    – Rusi
    Jul 15, 2022 at 11:28
  • 1
    ANother simpler option is just indent the whole src block with a space
    – Rusi
    Jul 15, 2022 at 11:33

2 Answers 2

2

The more idiomatic way to represent a combination of shell code and the output of that code in orgmode is to do something like this:

#+BEGIN_SRC sh :results verbatim
sudo update-alternatives --config python3
#+END_SRC

#+RESULTS:
: There are 2 choices for the alternative python3 (providing /usr/bin/python3).
: 
: Selection    Path                       Priority   Status
: ------------------------------------------------------------
: * 0            /usr/bin/python3.8          2         auto mode
: 1            /usr/bin/python3.8          2         manual mode
: 2            /usr/local/bin/python3.10   1         manual mode
: 
: Press <enter> to keep the current choice[*], or type selection number: 

With this formatting, you can execute the code block to automatically generate the output. Or, if you prefer to manually enter the output, you can just prefix each line with the : symbol, and omit the #+RESULTS: header.

2
  • "you can execute the code block to automatically generate the output." How so?
    – user19777
    Jul 15, 2022 at 16:08
  • With point in the source block, C-c C-c. There may be some configuration needed: orgmode.org/manual/…
    – Tyler
    Jul 15, 2022 at 16:42
1

The best way to create a block, is

  1. C-c C-,, choose s (or whatever) and choose bash (or whatever)
  2. It will create en empty block like so.
#+begin_src sh
#+end_src
  1. Put your cursor within that block and do C-c '. In the resulting buffer, copy the code, indent if needed, and press C-c C-c.

  2. You will get a block like this

#+begin_src sh
$ sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).

Selection    Path                       Priority   Status
------------------------------------------------------------
,* 0            /usr/bin/python3.8          2         auto mode
1            /usr/bin/python3.8          2         manual mode
2            /usr/local/bin/python3.10   1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 
#+end_src

Note the , before *. Indenting the block wouldn't work because org will think that the * is a bullet point.


Btw, what you have within your sh block is not all shell script. It is a combination of shell command, its output, and all manner of things. So, use some other block.

2
  • What is the long form of C-c '? For me, undefined.
    – user19777
    Jul 15, 2022 at 16:42
  • 1
    Are you doing it from an Org mode buffer? It should be bound to org-edit-special.
    – NickD
    Jul 15, 2022 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.