Bash¶
Bash is both an interactive shell and a scripting language. This section covers the fundamentals needed to work efficiently at the command line and build small, reliable scripts for system administration, automation, and security testing.
The examples are designed for authorized lab environments and real-world engagements where you have permission to test a system.
Learning Path¶
Shell and Script Fundamentals¶
- Bash Shell Scripts: Create, execute, and make scripts executable.
- Variables: Store values, use parameter expansion, manage scope, export variables, and work with arrays.
- Passing Arguments: Read positional arguments, validate input, and build reusable scripts.
- Executing Shell Commands: Use command substitution and understand subshell behavior.
- Reading User Input: Read single values, multiple values, and arrays from the terminal.
Script Control and Data Handling¶
- The
trapCommand: Handle signals, clean up temporary resources, and respond to errors. - Bash Arrays: Store collections of values and iterate over their contents.
if,else, andfiStatements: Branch based on conditions and file checks.- Comparisons: Compare numbers and strings.
- File Testing: Check files, directories, permissions, sizes, and symbolic links.
- Loops: Repeat work with
for,while, anduntil. - Functions: Organize reusable commands and pass arguments between functions.
Menus, Quoting, and Output¶
select: Build simple interactive terminal menus.case: Match values and patterns across multiple conditions.- Quotes and Quotations: Control expansion, whitespace, escaping, and command substitution.
- Arithmetic Operations: Perform integer, base-conversion, and floating-point calculations.
- Redirections: Manage standard input, output, errors, logging, and pipelines.
Security Applications¶
These Bash fundamentals support common security workflows such as:
- Automating reconnaissance and enumeration tasks.
- Processing command output and checking files or permissions.
- Running repeatable checks across hosts and services.
- Capturing output and errors for troubleshooting and reporting.
- Building small, auditable scripts for authorized testing.
Use explicit targets, validate input, quote variables, and avoid executing untrusted content directly from the network.