Bash/Shell Scripting

Bash/Shell scripting is the practice of writing programs for a command-line interpreter, or "shell," to automate tasks and manage system operations. As one of the most common and powerful shells, Bash (Bourne-Again SHell) allows users to create scripts—sequences of commands stored in a file—that can manipulate files, execute other programs, configure system environments, and orchestrate complex data-processing pipelines. This form of scripting is a fundamental skill for developers, system administrators, and data scientists working in Unix-like environments (such as Linux and macOS), enabling them to create efficient, repeatable workflows directly from the terminal.

  1. Introduction to the Shell and Scripting
    1. Understanding the Command Line Interface
      1. Definition and Purpose of the Shell
        1. Shell as a Command Interpreter
          1. Interactive vs Non-interactive Shells
            1. Login vs Non-login Shells
              1. Common Shell Types
                1. sh (Bourne Shell)
                  1. bash (Bourne-Again Shell)
                    1. zsh (Z Shell)
                      1. ksh (Korn Shell)
                        1. csh (C Shell)
                          1. tcsh (TENEX C Shell)
                            1. fish (Friendly Interactive Shell)
                            2. The Role of the Terminal Emulator
                              1. Terminal Emulators vs Virtual Consoles
                                1. Terminal Settings and Customization
                                  1. Color Schemes
                                    1. Font Configuration
                                      1. Key Bindings
                                  2. Basic Shell Navigation and Commands
                                    1. Manipulating Files and Directories
                                      1. touch (Create Empty Files)
                                        1. Creating Multiple Files
                                          1. Updating Timestamps
                                            1. Setting Specific Times
                                            2. mkdir (Create Directories)
                                              1. Creating Parent Directories (-p)
                                                1. Setting Permissions (-m)
                                                2. cp (Copy Files and Directories)
                                                  1. Copying Single Files
                                                    1. Copying Multiple Files
                                                      1. Copying Recursively (-r)
                                                        1. Preserving Attributes (-a)
                                                          1. Interactive Mode (-i)
                                                            1. Verbose Mode (-v)
                                                            2. mv (Move and Rename Files and Directories)
                                                              1. Moving Files
                                                                1. Renaming Files
                                                                  1. Interactive Mode (-i)
                                                                    1. Verbose Mode (-v)
                                                                    2. rm (Remove Files)
                                                                      1. Removing Single Files
                                                                        1. Removing Multiple Files
                                                                          1. Removing Directories (-r)
                                                                            1. Forcing Removal (-f)
                                                                              1. Interactive Mode (-i)
                                                                                1. Verbose Mode (-v)
                                                                                2. rmdir (Remove Empty Directories)
                                                                                  1. find (Search for Files and Directories)
                                                                                    1. Basic Syntax
                                                                                      1. Search by Name
                                                                                        1. Search by Type
                                                                                          1. Search by Size
                                                                                            1. Search by Time
                                                                                          2. Viewing File Contents
                                                                                            1. cat (Concatenate and Display Files)
                                                                                              1. Displaying Single Files
                                                                                                1. Concatenating Multiple Files
                                                                                                  1. Numbering Lines (-n)
                                                                                                  2. less (Paged Viewing)
                                                                                                    1. Search Functions
                                                                                                      1. Configuration Options
                                                                                                      2. more (Basic Paging)
                                                                                                        1. head (View Beginning of Files)
                                                                                                          1. Default Behavior
                                                                                                            1. Specifying Number of Lines (-n)
                                                                                                            2. tail (View End of Files)
                                                                                                              1. Default Behavior
                                                                                                                1. Specifying Number of Lines (-n)
                                                                                                                  1. Following File Growth (-f)
                                                                                                                    1. Following by Name (--follow=name)
                                                                                                                  2. Getting Help and Documentation
                                                                                                                    1. man (Manual Pages)
                                                                                                                      1. Section Numbers
                                                                                                                        1. Searching man Pages
                                                                                                                        2. info (Info Documents)
                                                                                                                          1. help (Built-in Help)
                                                                                                                            1. Command --help Option
                                                                                                                              1. which (Locate Commands)
                                                                                                                                1. whereis (Locate Binary, Source, and Manual)
                                                                                                                                  1. type (Display Command Type)
                                                                                                                                2. Your First Shell Script
                                                                                                                                  1. The Shebang Line
                                                                                                                                    1. Purpose and Syntax
                                                                                                                                      1. Common Shebang Lines
                                                                                                                                        1. #!/bin/bash
                                                                                                                                          1. #!/usr/bin/env bash
                                                                                                                                            1. #!/bin/sh
                                                                                                                                            2. Choosing the Right Shebang
                                                                                                                                            3. Creating and Saving a Script File
                                                                                                                                              1. Choosing a Text Editor
                                                                                                                                                1. nano
                                                                                                                                                  1. vim
                                                                                                                                                    1. emacs
                                                                                                                                                      1. VS Code
                                                                                                                                                      2. File Naming Conventions
                                                                                                                                                        1. Descriptive Names
                                                                                                                                                          1. Avoiding Spaces
                                                                                                                                                            1. Using Underscores or Hyphens
                                                                                                                                                            2. File Extensions
                                                                                                                                                              1. .sh Extension
                                                                                                                                                                1. No Extension Approach
                                                                                                                                                              2. Setting Execute Permissions
                                                                                                                                                                1. Understanding File Permissions
                                                                                                                                                                  1. Read, Write, Execute
                                                                                                                                                                    1. Owner, Group, Other
                                                                                                                                                                      1. Numeric Notation
                                                                                                                                                                        1. Symbolic Notation
                                                                                                                                                                        2. Using chmod +x
                                                                                                                                                                          1. Using chmod 755
                                                                                                                                                                          2. Running a Script
                                                                                                                                                                            1. Executing with Relative Path
                                                                                                                                                                              1. Executing with Absolute Path
                                                                                                                                                                                1. Running with bash script.sh
                                                                                                                                                                                  1. Adding Script Directory to PATH
                                                                                                                                                                                    1. Common Execution Errors
                                                                                                                                                                                      1. Permission Denied
                                                                                                                                                                                        1. Command Not Found
                                                                                                                                                                                          1. Bad Interpreter