Bash/Shell Scripting

  1. Core Scripting Concepts
    1. Variables
      1. Defining and Assigning Variables
        1. Basic Assignment Syntax
          1. No Spaces Around Equals Sign
            1. Case Sensitivity
            2. Naming Conventions
              1. Allowed Characters
                1. Letters
                  1. Numbers
                    1. Underscores
                    2. Starting with Letter or Underscore
                      1. Best Practices
                        1. Descriptive Names
                          1. Consistent Naming Style
                            1. Avoiding Reserved Words
                          2. Accessing Variable Values
                            1. Using Dollar Sign ($)
                              1. Using Curly Braces (${VAR})
                                1. When Braces Are Required
                                2. Environment Variables
                                  1. Definition and Purpose
                                    1. Exporting Variables (export)
                                      1. Common Environment Variables
                                        1. PATH
                                          1. HOME
                                            1. USER
                                              1. SHELL
                                                1. PWD
                                                  1. OLDPWD
                                                  2. Viewing Environment
                                                    1. env Command
                                                      1. printenv Command
                                                        1. set Command
                                                      2. Special Shell Variables
                                                        1. Exit Status ($?)
                                                          1. Process ID ($$)
                                                            1. Number of Arguments ($#)
                                                              1. All Arguments as Array ($@)
                                                                1. All Arguments as String ($*)
                                                                  1. Script Name ($0)
                                                                    1. Positional Parameters ($1, $2, ...)
                                                                      1. Last Background Process ID ($!)
                                                                      2. Variable Scope
                                                                        1. Local Variables
                                                                          1. Global Variables
                                                                            1. Subshell Variables
                                                                            2. Readonly Variables
                                                                              1. readonly Command
                                                                                1. declare -r
                                                                                2. Unsetting Variables
                                                                                  1. unset Command
                                                                                3. Quoting and Escaping
                                                                                  1. The Need for Quoting
                                                                                    1. Preventing Word Splitting
                                                                                      1. Preventing Globbing
                                                                                        1. Preserving Whitespace
                                                                                        2. Double Quotes
                                                                                          1. Variable Expansion
                                                                                            1. Command Substitution
                                                                                              1. Arithmetic Expansion
                                                                                                1. Preserving Most Special Characters
                                                                                                2. Single Quotes
                                                                                                  1. Literal Strings
                                                                                                    1. No Expansions
                                                                                                      1. Including Single Quotes in Strings
                                                                                                      2. Backslash Escaping
                                                                                                        1. Escaping Special Characters
                                                                                                          1. Escaping Newlines
                                                                                                            1. Common Escape Sequences
                                                                                                            2. ANSI-C Quoting ($'...')
                                                                                                              1. Escape Sequences
                                                                                                                1. Unicode Characters
                                                                                                              2. Input, Output, and Redirection
                                                                                                                1. Standard Streams
                                                                                                                  1. Standard Input (stdin, 0)
                                                                                                                    1. Standard Output (stdout, 1)
                                                                                                                      1. Standard Error (stderr, 2)
                                                                                                                      2. Output Redirection
                                                                                                                        1. Overwrite Redirection (>)
                                                                                                                          1. Append Redirection (>>)
                                                                                                                            1. Redirecting to Files
                                                                                                                              1. Redirecting to /dev/null
                                                                                                                              2. Input Redirection
                                                                                                                                1. Reading from Files (<)
                                                                                                                                  1. Reading from Standard Input
                                                                                                                                  2. Error Redirection
                                                                                                                                    1. Redirecting stderr (2>)
                                                                                                                                      1. Appending stderr (2>>)
                                                                                                                                        1. Combining stdout and stderr (&>)
                                                                                                                                          1. Redirecting stderr to stdout (2>&1)
                                                                                                                                          2. Here Documents
                                                                                                                                            1. Basic Syntax (<<)
                                                                                                                                              1. Delimiter Selection
                                                                                                                                                1. Quoting Delimiters
                                                                                                                                                  1. Indented Here Documents (<<-)
                                                                                                                                                  2. Here Strings
                                                                                                                                                    1. Basic Syntax (<<<)
                                                                                                                                                      1. Use Cases
                                                                                                                                                      2. Pipes
                                                                                                                                                        1. Basic Pipe Operator (|)
                                                                                                                                                          1. Chaining Multiple Commands
                                                                                                                                                            1. Named Pipes (FIFOs)
                                                                                                                                                            2. Process Substitution
                                                                                                                                                              1. Input Process Substitution (<())
                                                                                                                                                                1. Output Process Substitution (>())
                                                                                                                                                              2. Command Substitution
                                                                                                                                                                1. Backticks (Legacy Method)
                                                                                                                                                                  1. Basic Syntax
                                                                                                                                                                    1. Limitations
                                                                                                                                                                    2. Dollar-Parentheses (Modern Method)
                                                                                                                                                                      1. Basic Syntax ($())
                                                                                                                                                                        1. Advantages over Backticks
                                                                                                                                                                          1. Nesting Command Substitutions
                                                                                                                                                                          2. Capturing Command Output
                                                                                                                                                                            1. Error Handling in Command Substitution
                                                                                                                                                                            2. Arithmetic Operations
                                                                                                                                                                              1. Integer Arithmetic
                                                                                                                                                                                1. let Command
                                                                                                                                                                                  1. Double Parentheses ((...))
                                                                                                                                                                                    1. expr Command
                                                                                                                                                                                      1. Arithmetic Expansion $((...))
                                                                                                                                                                                      2. Arithmetic Operators
                                                                                                                                                                                        1. Addition (+)
                                                                                                                                                                                          1. Subtraction (-)
                                                                                                                                                                                            1. Multiplication (*)
                                                                                                                                                                                              1. Division (/)
                                                                                                                                                                                                1. Modulo (%)
                                                                                                                                                                                                  1. Exponentiation (**)
                                                                                                                                                                                                  2. Comparison Operators
                                                                                                                                                                                                    1. Equal (==)
                                                                                                                                                                                                      1. Not Equal (!=)
                                                                                                                                                                                                        1. Less Than (<)
                                                                                                                                                                                                          1. Greater Than (>)
                                                                                                                                                                                                            1. Less Than or Equal (<=)
                                                                                                                                                                                                              1. Greater Than or Equal (>=)
                                                                                                                                                                                                              2. Floating-Point Arithmetic
                                                                                                                                                                                                                1. bc Calculator
                                                                                                                                                                                                                  1. awk for Calculations
                                                                                                                                                                                                                  2. Increment and Decrement
                                                                                                                                                                                                                    1. Pre-increment (++var)
                                                                                                                                                                                                                      1. Post-increment (var++)
                                                                                                                                                                                                                        1. Pre-decrement (--var)
                                                                                                                                                                                                                          1. Post-decrement (var--)