#+OPTIONS: H:3 num:nil toc:2 \n:nil ::t |:t ^:{} -:t f:t *:t tex:t d:(HIDE) tags:not-in-toc broken-links:nil #+STARTUP: align fold nodlcheck hidestars oddeven lognotestate hideblocks #+SEQ_TODO: TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@) #+TAGS: Write(w) Update(u) Fix(f) Check(c) noexport(n) #+TITLE: Shell Code Blocks in Babel #+AUTHOR: Matt Trzcinski #+EMAIL: matt[at]excalamus[dot]com #+LANGUAGE: en #+HTML_LINK_UP: index.html #+HTML_LINK_HOME: https://orgmode.org/worg/ #+EXCLUDE_TAGS: noexport # TODO remove this #+options: toc:nil #+name: banner #+begin_export html
#+end_export * Template Checklist [4/12] :noexport: - [X] Revise #+TITLE: - [X] Indicate #+AUTHOR: - [X] Add #+EMAIL: - [X] Revise banner source block [3/3] - [X] Add link to a useful language web site - [X] Replace "Language" with language name - [X] Find a suitable graphic and use it to link to the language web site - [ ] Write an [[Introduction]] - [ ] Describe [[Requirements and Setup][Requirements and Setup]] - [ ] Replace "Language" with language name in [[Org Mode Features for Language Source Code Blocks][Babel Features for Language Source Code Blocks]] - [ ] Describe [[Header Arguments][Header Arguments]] - [ ] Describe support for [[Sessions]] - [ ] Describe [[Result Types][Result Types]] - [ ] Describe [[Other]] differences from supported languages - [ ] Provide brief [[Examples of Use][Examples of Use]] * Introduction # - Brief description of language. A shell is a user interface for interacting with system services. File management, process execution, and operating system monitoring can all be done with a shell. Many shells are plain text only whereas some support graphics or are themselves fully graphical. Similarities exist between shells and, though standards exist (such as POSIX[fn:1]), there is no guarantee that what works in one shell will work in another. Each shell is a separate application. Shells often provide a programming language as well as access to system utilities, such as the GNU Core Utilities[fn:2]. Users can stitch utilities together or create their own. # - Range of typical uses within Org Mode. Org Babel lets users run commands[fn:3] in separate shells... : #+begin_src sh :results output : echo PID: $$ : #+end_src : : #+RESULTS: : : PID: 9952 : : #+begin_src sh :results output : echo PID: $$ : #+end_src : : #+RESULTS: : : PID: 9990 : ...or as part of a shared session. : #+begin_src sh :results output :session shared : echo PID: $$ : export X=1 : #+end_src : : #+RESULTS: : : PID: 9742 : : #+begin_src sh :results output :session shared : echo PID: $$ : echo X was set to $X : #+end_src : : #+RESULTS: : : PID: 9742 : : X was set to 1 Shell blocks can run as standalone scripts or chained processes, be tangled, use args, work with stdin, have shebangs, and more. * Requirements and Setup # - Installation and configuration of language software Org Babel can run many different shells, including [[https://www.gnu.org/software/bash/][sh]], [[https://www.gnu.org/software/bash/][bash]], [[https://www.zsh.org/][zsh]], [[https://fishshell.com/][fish]], [[https://www.grymoire.com/unix/csh.html][csh]], [[https://www.in-ulm.de/~mascheck/various/ash/][ash]], [[http://gondor.apana.org.au/~herbert/dash/][dash]], [[http://www.kornshell.org/][ksh]], [[https://www.mirbsd.org/mksh.htm][mksh]], and [[https://packages.qa.debian.org/p/posh.html][posh]]. The primary requirement is that the shell be installed on the system. # - Emacs configuration # - Org-mode configuration (org-babel-do-load-languages) Once the shell is installed on the system, the Org Babel shell language facility must be set to load[fn:4]: #+begin_example emacs-lisp ;; active Babel languages (org-babel-do-load-languages 'org-babel-load-languages '((shell . t))) #+end_example *NOTE:* This is all that's needed, regardless of the shell you intend to use! The "shell"