🎓 Concepts Covered
- How to create a script file
- Basic output commands
- Running your first script
- Understanding script syntax
📋 Step-by-Step Instructions
Create a new file
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.
Write the code
Type the script code shown below. The echo command (Bash) or Write-Host (PowerShell) displays text on the screen.
Save the file
Save your script in a location you can easily find, like your home directory or Desktop.
Make it executable (Bash only)
In terminal, run: chmod +x hello.sh
This gives the script permission to run.
Run the script
Bash: ./hello.sh
PowerShell: .\hello.ps1
💻 Complete Code
Bash (hello.sh)
#!/bin/bash
# My first Bash script
echo "Hello, World!"
echo "Welcome to scripting!"
PowerShell (hello.ps1)
# My first PowerShell script
Write-Host "Hello, World!"
Write-Host "Welcome to scripting!"
▶️ Sample Output
Expected output:
Hello, World!
Welcome to scripting!
🎨 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
🎓 Concepts Covered
- Creating and using variables
- Storing text (strings) in variables
- Combining variables with text
- Variable naming conventions
📋 Step-by-Step Instructions
Understand variables
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)
Create variables for personal info
Store your name, age, and city in separate variables.
Display the greeting
Use the variables in your echo/Write-Host statements. In Bash, use $variable to access the value. PowerShell is the same!
Run and test
Execute your script and verify it displays your personal information correctly.
💻 Complete Code
Bash (greeting.sh)
#!/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!"
PowerShell (greeting.ps1)
# 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
Expected output:
==============================
PERSONAL PROFILE
==============================
Name: Sarah
Age: 25 years old
City: Portland
Hello, Sarah! Welcome to scripting from Portland!
🎨 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
🎓 Concepts Covered
- Reading user input
- Storing input in variables
- Making scripts interactive
- Prompting users effectively
📋 Step-by-Step Instructions
Learn the input commands
Bash: read variable_name waits for user input
PowerShell: Read-Host “prompt” asks and stores input
Ask multiple questions
Prompt the user for their name, favorite color, and a number. Store each response in a variable.
Echo back the responses
Display all the information the user provided in a friendly format.
💻 Complete Code
Bash (echo_input.sh)
#!/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!"
PowerShell (echo_input.ps1)
# 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
Example interaction:
===== Interactive Echo Program =====
What is your name?
John
What is your favorite color?
Blue
Pick a number between 1 and 100:
42
===== Here’s what you told me =====
Name: John
Favorite Color: Blue
Lucky Number: 42
Nice to meet you, John! Blue is a great color!
🎨 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
🎓 Concepts Covered
- Mathematical operations (+, -, *, /)
- Working with numbers in scripts
- Converting string input to numbers
- Displaying calculated results
📋 Step-by-Step Instructions
Understand arithmetic syntax
Bash: Use $((expression)) for math, e.g., $((5 + 3))
PowerShell: Math works directly, but convert input with [int]$variable
Get two numbers from user
Prompt for two numbers and store them in variables.
Perform all operations
Calculate sum, difference, product, and quotient. Store each result in its own variable.
Display results
Show all calculated results in a clear, formatted way.
💻 Complete Code
Bash (calculator.sh)
#!/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!"
PowerShell (calculator.ps1)
# 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
Example with inputs 10 and 5:
====== Simple Calculator ======
Enter first number:
10
Enter second number:
5
====== Results ======
10 + 5 = 15
10 – 5 = 5
10 × 5 = 50
10 ÷ 5 = 2
Thanks for calculating!
🎨 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
🎓 Concepts Covered
- Creating files from scripts
- Writing text to files
- File redirection (>, >>)
- Working with file paths
💻 Complete Code
Bash (file_creator.sh)
#!/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
PowerShell (file_creator.ps1)
# 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
Example interaction:
====== File Creator ======
Enter filename (e.g., mynotes.txt):
test.txt
Enter file content:
This is my first file!
✓ File ‘test.txt’ created successfully!
Content: This is my first file!
Location: /home/user/test.txt
🎨 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
🎓 Concepts Covered
- Checking if files exist
- Reading file properties (size, date)
- Basic if-statements
- File tests and conditions
💻 Complete Code
Bash (file_info.sh)
#!/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
PowerShell (file_info.ps1)
# 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
Example output:
====== File Information Display ======
Enter filename:
test.txt
File: test.txt
Size: 245 bytes
Lines: 8
Words: 42
Modified: 2025-10-13 14:30:22
— First 5 lines —
This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
🎨 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
🎯 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