Shell Fundamentals

Overview

Understanding your shell is essential for effective system administration. These topics cover the patterns, redirections, and process controls that make bash powerful.

In This Section

Topic Description

Shell Patterns

Heredocs, parameter expansion, arrays, brace expansion, and defensive scripting.

I/O Redirection

stdin, stdout, stderr, file descriptors, and advanced redirection patterns.

Process Management

Jobs, background processes, signals, and process control.

Key Concepts

Parameter Expansion Quick Reference

${VAR:-default}    # Use default if unset/empty
${VAR:=default}    # Set and use default if unset/empty
${VAR##pattern}    # Remove longest prefix match
${VAR%%pattern}    # Remove longest suffix match
${VAR//old/new}    # Replace all occurrences

Redirection Essentials

cmd > file         # stdout to file
cmd 2> file        # stderr to file
cmd &> file        # both to file
cmd 2>&1           # stderr to stdout
cmd < file         # stdin from file

Process Control

cmd &              # Run in background
Ctrl+Z             # Suspend foreground
bg                 # Resume in background
fg                 # Bring to foreground
jobs               # List jobs

Learning Path

  1. Master I/O Redirection - everything flows through streams

  2. Learn Shell Patterns for scripting and one-liners

  3. Understand Process Management for job control