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