Bash/Shell Scripting

  1. Advanced Scripting Techniques
    1. Command-Line Argument Processing
      1. Positional Parameters
        1. Accessing Arguments ($1, $2, ...)
          1. Number of Arguments ($#)
            1. All Arguments ($@ vs $*)
            2. Shifting Arguments
              1. shift Command
                1. Processing Variable Arguments
                2. Option Processing with getopts
                  1. Basic getopts Usage
                    1. Short Options
                      1. Options with Arguments
                        1. Error Handling
                          1. OPTARG and OPTIND Variables
                          2. Long Option Processing
                            1. Manual Parsing
                              1. Using getopt Command
                              2. Creating Usage Messages
                                1. Help Functions
                                  1. Error Messages
                                    1. Exit Codes
                                  2. Process Management
                                    1. Background Processes
                                      1. Running Commands in Background (&)
                                        1. Disowning Processes (disown)
                                          1. nohup Command
                                          2. Job Control
                                            1. Listing Jobs (jobs)
                                              1. Foreground Jobs (fg)
                                                1. Background Jobs (bg)
                                                  1. Job Specifications (%1, %2, etc.)
                                                  2. Process Information
                                                    1. Process IDs ($$, $!)
                                                      1. Parent Process ID ($PPID)
                                                        1. ps Command
                                                          1. pgrep and pkill
                                                          2. Process Communication
                                                            1. Exit Codes
                                                              1. Signals
                                                                1. Inter-Process Communication
                                                                2. Waiting for Processes
                                                                  1. wait Command
                                                                    1. Waiting for Specific Processes
                                                                      1. Timeout Handling
                                                                    2. Signal Handling and Traps
                                                                      1. Understanding Signals
                                                                        1. Signal Types
                                                                          1. Signal Numbers
                                                                            1. Default Signal Handlers
                                                                            2. The trap Command
                                                                              1. Basic Syntax
                                                                                1. Setting Signal Handlers
                                                                                  1. Removing Traps
                                                                                  2. Common Signals
                                                                                    1. SIGINT (Interrupt)
                                                                                      1. SIGTERM (Terminate)
                                                                                        1. SIGKILL (Kill)
                                                                                          1. SIGHUP (Hangup)
                                                                                            1. SIGUSR1 and SIGUSR2
                                                                                              1. EXIT Pseudo-signal
                                                                                              2. Practical Applications
                                                                                                1. Cleanup on Exit
                                                                                                  1. Graceful Shutdown
                                                                                                    1. Temporary File Management
                                                                                                      1. Lock File Handling
                                                                                                    2. Subshells and Command Grouping
                                                                                                      1. Subshells with Parentheses
                                                                                                        1. Creating Isolated Environments
                                                                                                          1. Variable Scope in Subshells
                                                                                                            1. Directory Changes in Subshells
                                                                                                              1. Exit Status from Subshells
                                                                                                              2. Command Grouping with Braces
                                                                                                                1. Grouping Commands in Current Shell
                                                                                                                  1. Redirection with Command Groups
                                                                                                                    1. Conditional Command Groups
                                                                                                                    2. Differences Between Subshells and Groups
                                                                                                                      1. Performance Considerations
                                                                                                                      2. Shell Parameter Expansion
                                                                                                                        1. Basic Parameter Expansion
                                                                                                                          1. ${parameter}
                                                                                                                            1. Parameter Existence
                                                                                                                            2. Default Values
                                                                                                                              1. ${parameter:-default}
                                                                                                                                1. ${parameter:=default}
                                                                                                                                  1. ${parameter:?error}
                                                                                                                                    1. ${parameter:+alternate}
                                                                                                                                    2. String Length
                                                                                                                                      1. ${#parameter}
                                                                                                                                      2. Substring Extraction
                                                                                                                                        1. ${parameter:offset}
                                                                                                                                          1. ${parameter:offset:length}
                                                                                                                                          2. Pattern Matching and Replacement
                                                                                                                                            1. Remove Shortest Match (${parameter#pattern})
                                                                                                                                              1. Remove Longest Match (${parameter##pattern})
                                                                                                                                                1. Remove from End (${parameter%pattern})
                                                                                                                                                  1. Remove from End Longest (${parameter%%pattern})
                                                                                                                                                  2. String Replacement
                                                                                                                                                    1. Replace First Match (${parameter/pattern/string})
                                                                                                                                                      1. Replace All Matches (${parameter//pattern/string})
                                                                                                                                                        1. Replace at Beginning (${parameter/#pattern/string})
                                                                                                                                                          1. Replace at End (${parameter/%pattern/string})
                                                                                                                                                          2. Case Modification
                                                                                                                                                            1. Uppercase (${parameter^^})
                                                                                                                                                              1. Lowercase (${parameter,,})
                                                                                                                                                                1. Capitalize (${parameter^})
                                                                                                                                                              2. Other Shell Expansions
                                                                                                                                                                1. Brace Expansion
                                                                                                                                                                  1. Sequence Generation ({1..10})
                                                                                                                                                                    1. String Lists ({a,b,c})
                                                                                                                                                                      1. Nested Braces
                                                                                                                                                                      2. Tilde Expansion
                                                                                                                                                                        1. Home Directory (~)
                                                                                                                                                                          1. User Home Directories (~user)
                                                                                                                                                                          2. Pathname Expansion (Globbing)
                                                                                                                                                                            1. Wildcards (*, ?, [...])
                                                                                                                                                                              1. Extended Globbing
                                                                                                                                                                                1. Recursive Globbing (**)
                                                                                                                                                                                  1. Dotglob Option
                                                                                                                                                                                  2. Command Substitution
                                                                                                                                                                                    1. Modern Syntax $()
                                                                                                                                                                                      1. Legacy Syntax ``
                                                                                                                                                                                        1. Nested Substitutions
                                                                                                                                                                                        2. Arithmetic Expansion
                                                                                                                                                                                          1. Basic Syntax $((...))
                                                                                                                                                                                            1. Variables in Arithmetic
                                                                                                                                                                                              1. Complex Expressions