Shell/CLI/TUI and ~ Environments

The command-line interface (CLI) is the most direct way to interact with a Unix-like operating system. It provides a text-based environment where users type commands, receive output, and compose complex workflows through scripting.

The Shell

The shell is a command interpreter that reads user input, executes programs, and manages the environment. Common shells include:

  • bash: The Bourne-Again Shell, default on many systems.
  • zsh: Z Shell, with advanced completion and scripting.
  • fish: Friendly Interactive SHell, with user-friendly defaults.
  • dash: Minimal POSIX-compliant shell, used for scripts on Debian systems.

Shell Features

  • Command execution: Running programs by name.
  • Redirection: Redirecting stdin, stdout, stderr (>, <, >>, 2>).
  • Pipes: Connecting commands (|).
  • Variables: Environment and shell variables.
  • Control structures: if, for, while, case.
  • Functions: Reusable command sequences.
  • Job control: Backgrounding, suspending, and resuming processes.
  • History: Command history and recall.

Environment Variables

The shell maintains an environment passed to child processes. Key variables:

echo $PATH        # Search path for executables
echo $HOME        # User home directory
echo $SHELL       # Path to current shell
echo $EDITOR      # Preferred text editor
echo $LANG        # Locale settings

The ~ character is shorthand for $HOME:

cd ~/projects
ls ~/.config

TUI: Text-Based User Interfaces

Text User Interfaces (TUIs) provide full-screen, interactive text interfaces. They use terminal control sequences to position text, handle keyboard input, and draw widgets.

Examples include:

  • htop: Interactive process viewer.
  • nano: Simple text editor with menus.
  • vim: Modal text editor with extensive features.
  • less: Pager with navigation and search.
  • midnight_commander: File manager with two panels.
  • tmux: Terminal multiplexer for session management.
  • screen: Older terminal multiplexer.

Terminal Emulators

On graphical systems, terminal emulators provide the window for CLI and TUI interaction:

  • xterm: Classic X11 terminal emulator.
  • gnome-terminal: GNOME desktop terminal.
  • konsole: KDE desktop terminal.
  • kitty: GPU-accelerated terminal emulator.
  • alacritty: Cross-platform GPU terminal.
  • wezterm: Cross-platform terminal and multiplexer.

Shell Configuration

Shell configuration files initialise the environment:

  • ~/.bashrc: Interactive bash configuration.
  • ~/.bash_profile: Login shell configuration.
  • ~/.zshrc: Zsh configuration.
  • ~/.config/fish/config.fish: Fish configuration.

Common configurations include aliases, prompt customisation, and PATH modification.