DevOps

UNIX Shells

Michael L. Collard, Ph.D.

Department of Computer Science, The University of Akron

Interface

  • Computing existed before GUIs:
  • UNIX created 1971
  • First GUIs not until 1980s (Apple Mac 1984, MS Windows 1.0 1985
  • Accessed and controlled via a CLI (Command Line Interface)
  • Currently:
  • Many server tasks do not benefit from a GUI
  • Web-based interfaces for configuration

Command Line Interface (CLI)

  • Start application programs
  • File handling
  • System administration
  • Basically, layer over the kernel API
  • Scripting language
  • Internal (built-in to shell) and external commands (separate programs)

CLI Advantages

  • Uniform Interface Offers a consistent interface for various commands, enhancing learning.
  • Enhanced Composability Facilitates complex operations through simple command combinations via piping and redirection.
  • Easy Installation Simplifies the installation of tools and software with just a few commands.
  • Scriptable and Automatable Enables creation of scripts for task automation, from simple aliases to complex programs.
  • Efficient Resource Usage Uses fewer resources than GUIs by avoiding graphical rendering, enhancing efficiency.
  • Remote Operation Facilitates remote command execution on machines via tools like SSH, crucial for server management.
  • Precise Control Provides greater control and precision in system and software operations with detailed parameters.
  • Speed for Experts Allows proficient users to complete tasks faster than GUI, bypassing menu navigation.
  • Comprehensive Help Includes built-in help systems like man pages, offering extensive documentation.
  • Customizable Workflow Allows extensive customization for personalized environments and workflows.
  • Consistent System Experience Maintains consistency across various operating system versions and distributions.

CLI Disadvantages

  • Steep Learning Curve Intimidating to new users, and learning various commands and their syntax requires time and effort.
  • Less Intuitive Without visual cues and navigation, new users might find it challenging to discover features or remember complex commands, making CLIs less intuitive than GUIs.
  • Poor Accessibility Rely heavily on text and have limited visual customization options.
  • Limited Graphics and Multimedia Support Not designed for tasks that require graphical interfaces, like image editing or video playback.
  • Inconvenient for Casual Users Remembering specific commands and their syntax can be inconvenient.
  • Complexity in Handling File and Directory Structures Navigating and manipulating file systems through a CLI can be complex and less straightforward.
  • Difficulty in Editing Text and Commands Editing commands and texts in a CLI can be less efficient, particularly for those not familiar with text editors like Vim or Emacs.
  • Limited Appeal for Non-technical Users Less attractive to non-technical users.
  • Dependency on Keyboard Proficiency Requires good keyboard skills.

Thompson shell (sh)

  • Ken Thompson, 1971
  • First Unix shell in the first release of Unix
  • Simple command interpreter
  • Not really a scripting language

Bourne shell (sh)

  • Stephen Bourne, ATT&T Bell Labs (1977)
  • /bin/sh - Replacement for Thomson shell
  • Released in 1977 as the default Unix shell of Unix Version 7
  • Default shell for the root (superuser) account
  • Descendants: ksh, rc, bash, dash

C Shell (csh)

  • Bill Joy for BSD, 1978
  • Derived from Thompson shell (original sh)
  • Syntax modeled after C
  • Good job control features, history
  • tcsh – C shell (csh) with features, e.g., command-line editing
  • Typical usage:
  • C Shell (csh) for interactive use (or tcsh)
  • Bourne shell (sh) for scripting

Korn shell (ksh)

  • David Korn, 1988 (ksh88)
  • Syntax of Bourne shell (sh) and features of C Shell (csh)
  • Basis for POSIX shell
  • Ksh93
  • Variants: dtksh (part of CDE), tksh (with Tk)

Bash Shell (bash)

  • “Bourne-Again” shell
  • GNU Project, 1987
  • Superset of Bourne shell (sh)
  • Features of C Shell (csh), and tcsh
  • Default for most modern Linux distributions, Mac OS X, Cygwin
  • “bashisms” – features/behavior not in Bourne shell (sh)

Other Shells

  • rc – replacement for sh on Plan 9
  • ash, Almquist shell, A Shell – clone for BSD of much of Bourne shell
  • dash – Debian Almquist shell, faster than bash, but no extensions (no “bashisms”)
  • esh – Easy Shell, Lisp based
  • scsh – Scheme shell
  • sash – Standalone shell, no reliance on external libraries
  • zsh – Z Shell extension of Bourne shell (macOS default since 2019)

Current Practice

  • /bin/sh – Bourne shell, default for root account
  • /bin/bash – Bourne-Again shell, default for users
  • Often, /bin/sh alias for /bin/bash, but may not support same features
  • /etc/shells – list of installed shells
  • Other shells provided for compatibility with existing scripts