π 20 Scripts Every Beginner Should Write
Master Bash & PowerShell by building real scripts that solve actual problems. Each script builds on the previous one!
Hello World Beginner
π Display a simple message to the screen
π Concepts Covered
- How to create a script file
- Basic output commands
- Running your first script
- Understanding script syntax
π Step-by-Step Instructions
Bash: Create a file called hello.sh
PowerShell: Create a file called hello.ps1
Use any text editor like Notepad, nano, vim, or VS Code.
Type the script code shown below. The echo command (Bash) or Write-Host (PowerShell) displays text on the screen.
Save your script in a location you can easily find, like your home directory or Desktop.
In terminal, run: chmod +x hello.sh
This gives the script permission to run.
Bash: ./hello.sh
PowerShell: .\hello.ps1
π» Complete Code
#!/bin/bash
# My first Bash script
echo "Hello, World!"
echo "Welcome to scripting!"
# My first PowerShell script
Write-Host "Hello, World!"
Write-Host "Welcome to scripting!"
βΆοΈ Sample Output
π¨ 3 Ways to Customize
- Add more messages: Add additional echo or Write-Host lines with different text
- Use colors (PowerShell): Try Write-Host “Hello!” -ForegroundColor Green
- Add ASCII art: Display fun text art like:
_ _ _ _ | | | | ___| | | ___ | |_| |/ _ \ | |/ _ \ | _ | __/ | | (_) | |_| |_|\___|_|_|\___/
β οΈ Common Mistakes
- Forgetting the shebang (Bash): The #!/bin/bash line tells the system how to run the script
- Wrong file extension: Use .sh for Bash and .ps1 for PowerShell
- Not making executable (Bash): Must run chmod +x before running
- Typos in commands: Commands must be spelled exactly right (case matters in Bash!)
β Success Criteria
You’ve succeeded if:
- The script runs without errors
- You see “Hello, World!” displayed on the screen
- You can run the script multiple times
Personal Greeting Beginner
π Greet yourself using variables to store your name
π Concepts Covered
- Creating and using variables
- Storing text (strings) in variables
- Combining variables with text
- Variable naming conventions
π Step-by-Step Instructions
Variables are like labeled boxes that store information. You can put a value in the box and use it later.
Bash syntax: name=”value” (no spaces around =)
PowerShell syntax: $name = “value” (spaces OK)
Store your name, age, and city in separate variables.
Use the variables in your echo/Write-Host statements. In Bash, use $variable to access the value. PowerShell is the same!
Execute your script and verify it displays your personal information correctly.
π» Complete Code
#!/bin/bash
# Personal greeting with variables
name="Sarah"
age=25
city="Portland"
echo "=============================="
echo " PERSONAL PROFILE"
echo "=============================="
echo ""
echo "Name: $name"
echo "Age: $age years old"
echo "City: $city"
echo ""
echo "Hello, $name! Welcome to scripting from $city!"
# Personal greeting with variables
$name = "Sarah"
$age = 25
$city = "Portland"
Write-Host "==============================" -ForegroundColor Cyan
Write-Host " PERSONAL PROFILE" -ForegroundColor Cyan
Write-Host "==============================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Name: $name"
Write-Host "Age: $age years old"
Write-Host "City: $city"
Write-Host ""
Write-Host "Hello, $name! Welcome to scripting from $city!" -ForegroundColor Green
βΆοΈ Sample Output
π¨ 3 Ways to Customize
- Add more fields: Include favorite color, hobby, or occupation
- Calculate birth year: Add birth_year=$((2025 – age)) and display it
- Create a bio paragraph: Combine all variables into one personalized story
β οΈ Common Mistakes
- Spaces around = (Bash): name = “Sarah” won’t workβmust be name=”Sarah”
- Forgetting $ when using variable: echo name prints “name” literally, not the value
- Quotes matter: Use quotes for text values to avoid issues with spaces
- Case sensitivity (Bash): $Name and $name are different variables!
β Success Criteria
You’ve succeeded if:
- Your script displays all three pieces of information
- Variables are correctly inserted into sentences
- You can change variable values and see updated output
Interactive Echo Beginner
π Ask the user for input and echo it back
π Concepts Covered
- Reading user input
- Storing input in variables
- Making scripts interactive
- Prompting users effectively
π Step-by-Step Instructions
Bash: read variable_name waits for user input
PowerShell: Read-Host “prompt” asks and stores input
Prompt the user for their name, favorite color, and a number. Store each response in a variable.
Display all the information the user provided in a friendly format.
π» Complete Code
#!/bin/bash
# Interactive input and echo
echo "===== Interactive Echo Program ====="
echo ""
echo "What is your name?"
read name
echo "What is your favorite color?"
read color
echo "Pick a number between 1 and 100:"
read number
echo ""
echo "===== Here's what you told me ====="
echo "Name: $name"
echo "Favorite Color: $color"
echo "Lucky Number: $number"
echo ""
echo "Nice to meet you, $name! $color is a great color!"
# Interactive input and echo
Write-Host "===== Interactive Echo Program =====" -ForegroundColor Cyan
Write-Host ""
$name = Read-Host "What is your name?"
$color = Read-Host "What is your favorite color?"
$number = Read-Host "Pick a number between 1 and 100"
Write-Host ""
Write-Host "===== Here's what you told me =====" -ForegroundColor Yellow
Write-Host "Name: $name"
Write-Host "Favorite Color: $color"
Write-Host "Lucky Number: $number"
Write-Host ""
Write-Host "Nice to meet you, $name! $color is a great color!" -ForegroundColor Green
βΆοΈ Sample Output
π¨ 3 Ways to Customize
- Add more questions: Ask about age, city, hobby, or favorite food
- Do math with the number: Multiply their number by 2 and show the result
- Hidden input (Bash): Use read -s password for secret input (like passwords)
β οΈ Common Mistakes
- Not waiting for input: Make sure your script pauses for the user to type
- Empty inputs: Users might press Enter without typing anything
- Spelling variable names: If you store in $name, you must use $name (not $username)
β Success Criteria
You’ve succeeded if:
- Script asks questions and waits for answers
- All inputs are correctly echoed back
- The conversation feels natural and friendly
Simple Calculator Easy
π Perform basic math operations on user-provided numbers
π Concepts Covered
- Mathematical operations (+, -, *, /)
- Working with numbers in scripts
- Converting string input to numbers
- Displaying calculated results
π Step-by-Step Instructions
Bash: Use $((expression)) for math, e.g., $((5 + 3))
PowerShell: Math works directly, but convert input with [int]$variable
Prompt for two numbers and store them in variables.
Calculate sum, difference, product, and quotient. Store each result in its own variable.
Show all calculated results in a clear, formatted way.
π» Complete Code
#!/bin/bash
# Simple calculator
echo "====== Simple Calculator ======"
echo ""
read -p "Enter first number: " num1
read -p "Enter second number: " num2
# Perform calculations
sum=$((num1 + num2))
difference=$((num1 - num2))
product=$((num1 * num2))
quotient=$((num1 / num2))
# Display results
echo ""
echo "====== Results ======"
echo "$num1 + $num2 = $sum"
echo "$num1 - $num2 = $difference"
echo "$num1 Γ $num2 = $product"
echo "$num1 Γ· $num2 = $quotient"
echo ""
echo "Thanks for calculating!"
# Simple calculator
Write-Host "====== Simple Calculator ======" -ForegroundColor Cyan
Write-Host ""
$num1 = Read-Host "Enter first number"
$num2 = Read-Host "Enter second number"
# Convert to integers and perform calculations
$num1 = [int]$num1
$num2 = [int]$num2
$sum = $num1 + $num2
$difference = $num1 - $num2
$product = $num1 * $num2
$quotient = $num1 / $num2
# Display results
Write-Host ""
Write-Host "====== Results ======" -ForegroundColor Yellow
Write-Host "$num1 + $num2 = $sum" -ForegroundColor Green
Write-Host "$num1 - $num2 = $difference" -ForegroundColor Green
Write-Host "$num1 Γ $num2 = $product" -ForegroundColor Green
Write-Host "$num1 Γ· $num2 = $quotient" -ForegroundColor Green
Write-Host ""
Write-Host "Thanks for calculating!" -ForegroundColor Cyan
βΆοΈ Sample Output
π¨ 3 Ways to Customize
- Add modulo operation: Show remainder with $((num1 % num2))
- Add exponentiation: Calculate $((num1 ** num2)) (num1 to the power of num2)
- Check for division by zero: Add a warning if num2 is 0 before dividing
β οΈ Common Mistakes
- Forgetting $(( )) in Bash: Math operations need double parentheses
- Not converting to numbers (PowerShell): Input is text by defaultβconvert with [int]
- Division by zero: If user enters 0 as second number, division fails
- Integer division: 10 / 3 = 3 (not 3.33) unless you handle decimals specially
β Success Criteria
You’ve succeeded if:
- All four operations calculate correctly
- Results match what you’d expect from a calculator
- Script works with different number combinations
File Creator Easy
π Create a new text file with user-provided content
π Concepts Covered
- Creating files from scripts
- Writing text to files
- File redirection (>, >>)
- Working with file paths
π» Complete Code
#!/bin/bash
# Create a file with user content
echo "====== File Creator ======"
echo ""
read -p "Enter filename (e.g., mynotes.txt): " filename
read -p "Enter file content: " content
# Create the file with content
echo "$content" > "$filename"
if [ -f "$filename" ]; then
echo ""
echo "β File '$filename' created successfully!"
echo "Content: $content"
echo "Location: $(pwd)/$filename"
else
echo "β Error: Failed to create file"
fi
# Create a file with user content
Write-Host "====== File Creator ======" -ForegroundColor Cyan
Write-Host ""
$filename = Read-Host "Enter filename (e.g., mynotes.txt)"
$content = Read-Host "Enter file content"
# Create the file with content
$content | Out-File $filename
if (Test-Path $filename) {
Write-Host ""
Write-Host "β File '$filename' created successfully!" -ForegroundColor Green
Write-Host "Content: $content"
Write-Host "Location: $(Get-Location)\$filename"
}
else {
Write-Host "β Error: Failed to create file" -ForegroundColor Red
}
βΆοΈ Sample Output
π¨ 3 Ways to Customize
- Add timestamp: Include creation date/time in the file
- Multiple lines: Allow user to enter multiple lines of content
- Choose directory: Let user specify where to save the file
β οΈ Common Mistakes
- Overwriting files: Using > replaces existing filesβcheck if file exists first
- Special characters in filename: Avoid spaces and symbols like /, \, :, *, ?
- File permissions: Make sure you have write permission in the directory
β Success Criteria
You’ve succeeded if:
- A new file appears in your directory
- Opening the file shows the content you entered
- Success message displays the correct file path
File Info Display Easy
π Show detailed information about a file
π Concepts Covered
- Checking if files exist
- Reading file properties (size, date)
- Basic if-statements
- File tests and conditions
π» Complete Code
#!/bin/bash
# Display file information
echo "====== File Information Display ======"
echo ""
read -p "Enter filename: " filename
if [ -f "$filename" ]; then
echo ""
echo "File: $filename"
echo "Size: $(wc -c < "$filename") bytes"
echo "Lines: $(wc -l < "$filename")"
echo "Words: $(wc -w < "$filename")"
echo "Modified: $(stat -c %y "$filename" 2>/dev/null || stat -f %Sm "$filename")"
echo ""
echo "--- First 5 lines ---"
head -5 "$filename"
else
echo "β Error: File '$filename' not found"
fi
# Display file information
Write-Host "====== File Information Display ======" -ForegroundColor Cyan
Write-Host ""
$filename = Read-Host "Enter filename"
if (Test-Path $filename) {
$file = Get-Item $filename
$content = Get-Content $filename
Write-Host ""
Write-Host "File: $($file.Name)" -ForegroundColor Yellow
Write-Host "Size: $($file.Length) bytes"
Write-Host "Lines: $($content.Count)"
Write-Host "Modified: $($file.LastWriteTime)"
Write-Host ""
Write-Host "--- First 5 lines ---" -ForegroundColor Cyan
$content | Select-Object -First 5
}
else {
Write-Host "β Error: File '$filename' not found" -ForegroundColor Red
}
βΆοΈ Sample Output
π¨ 3 Ways to Customize
- Show last lines: Display the last 5 lines instead of first
- Calculate MB/GB: Convert bytes to megabytes for large files
- File type detection: Identify if it’s a text file, image, etc.
β οΈ Common Mistakes
- File doesn’t exist: Always check with -f (Bash) or Test-Path (PowerShell)
- Binary files: Don’t try to read binary files as text (images, executables)
- File paths with spaces: Always quote variables: “$filename”
β Success Criteria
- Script correctly identifies when file exists or doesn’t
- All file properties display accurately
- First 5 lines show correctly for text files
π Complete Script Index
Your complete learning journey from beginner to confident scripter
π― Scripts 1-5: Fundamentals
- Hello World – Basic output (5 min)
- Personal Greeting – Variables (8 min)
- Interactive Echo – User input (10 min)
- Simple Calculator – Math operations (12 min)
- File Creator – File writing (12 min)
π― Scripts 6-10: File Operations
- File Info Display – Reading properties (15 min)
- Multiple File Creator – Loops basics (18 min)
- File Organizer – Loops + conditions (20 min)
- Text Search – String searching (20 min)
- Backup Script – Copying with timestamps (25 min)
π― Scripts 11-15: Intermediate Skills
- Log File Cleaner – File deletion logic (25 min)
- Disk Space Monitor – System info (30 min)
- Process Lister – System processes (30 min)
- Password Generator – Random data (25 min)
- To-Do List Manager – File read/write/append (35 min)
π― Scripts 16-20: Advanced Integration
- User Account Creator – Input validation (40 min)
- System Health Report – Multiple checks (45 min)
- Automated Backup – Combining concepts (50 min)
- Log Analyzer – Text processing (50 min)
- Multi-Tool Menu – Complete application (60 min)
π Learning Path Summary
- Total Time: ~9 hours of hands-on practice
- Progression: Each script builds on previous concepts
- By Script 20: You’ll have a complete toolset of reusable scripts
- Skill Level: From absolute beginner to confident scripter
β What You’ll Achieve
After completing all 20 scripts, you will be able to:
- Write scripts confidently in both Bash and PowerShell
- Automate everyday tasks and save hours of work
- Handle files, directories, and system operations
- Create interactive tools with menus and user input
- Debug common errors and customize existing scripts
- Read and understand other people’s scripts
- Build your own automation tools from scratch
