← Script House
Scripting
CLH-007 of 015

Shell Scripting Basics

Automate everything. Why type commands 100 times when a script does it once?

Why Shell Scripts?

Shell scripts are the automation backbone of Linux. Security professionals use them to automate reconnaissance, process logs, deploy tools, and create custom utilities. A single script can replace hours of manual work.

Your First Script

#!/bin/bash # My first security script echo "=== System Recon ===" echo "Hostname:" $(hostname) echo "Current user:" $(whoami) echo "IP Address:" $(hostname -I) echo "Kernel:" $(uname -r)

Save as recon.sh, make executable with chmod +x recon.sh, then run with ./recon.sh

Essential Concepts

Shebang (#!/bin/bash)

First line tells the system which interpreter to use. Always include it.

Variables

NAME="value" to set, $NAME to use. No spaces around =

Command Substitution

$(command) captures output. Example: DATE=$(date)

Arguments

$1, $2 are arguments. $# = count, $@ = all

Loops and Conditionals

# Port scanner example for port in 22 80 443 8080; do if nc -z -w1 $1 $port 2>/dev/null; then echo "[OPEN] Port $port" fi done

Run with: ./scanner.sh 192.168.1.1

LAB: Script Workshop

Build a system reconnaissance script! Write code in the editor and click Run to execute it. Complete all objectives to master scripting basics.

Add the proper shebang line
Create and use a variable
Use command substitution
Echo at least 3 pieces of system info
recon.sh
Output
Ready to run your script... Try these commands in your script: • echo "message" • hostname • whoami • date • uname -r • id
Hints: Start with #!/bin/bash, create a variable like USER=$(whoami), then use echo to display information.
SCRIPT COMPLETE!

You've created a working reconnaissance script!

Skills demonstrated: Shebang, variables, command substitution, echo output.

Ready to Test Your Skills?

Completing CLH-007 to CLH-009 earns: CLI Specialist