Making Scripts Dynamic
To make scripts truly useful for security automation, we need control structures like variables and loops.
Variables
Variables store data. You define them without a $ but use $ to reference them.
bash #!/bin/bash TARGET_IP="192.168.1.10" PORT="80"
echo "Scanning target: $TARGET_IP on port $PORT"
The 'echo' command now uses the variable values
Loops (The for loop)
Loops allow you to iterate over a list of items (e.g., a list of IP addresses or usernames).
bash #!/bin/bash
Iterate over a list of common ports
for port in 21 22 23 80 443; do echo "Checking port: $port" # In a real script, this would be where you run a tool like nmap done
Bash scripting is essential for quickly automating reconnaissance and analysis tasks.