20 Scripts Every Beginner Should Write

πŸ“š 20 Scripts Every Beginner Should Write

Master Bash & PowerShell by building real scripts that solve actual problems. Each script builds on the previous one!

⏱️ Progressive Learning Path β€’ 🎯 Beginner to Confident
Script #1

Hello World Beginner

πŸ“ Display a simple message to the screen

🎯
What You’ll Learn Basic output, running scripts
⏱️
Estimated Time 5 minutes
πŸ”§
Tools Needed Terminal/PowerShell, text editor

πŸŽ“ 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

  1. Add more messages: Add additional echo or Write-Host lines with different text
  2. Use colors (PowerShell): Try Write-Host “Hello!” -ForegroundColor Green
  3. 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
Script #2

Personal Greeting Beginner

πŸ“ Greet yourself using variables to store your name

🎯
What You’ll Learn Variables, string manipulation
⏱️
Estimated Time 8 minutes
πŸ”§
Tools Needed Terminal/PowerShell, text editor

πŸŽ“ 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

  1. Add more fields: Include favorite color, hobby, or occupation
  2. Calculate birth year: Add birth_year=$((2025 – age)) and display it
  3. 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
Script #3

Interactive Echo Beginner

πŸ“ Ask the user for input and echo it back

🎯
What You’ll Learn User input, interactive scripts
⏱️
Estimated Time 10 minutes
πŸ”§
Tools Needed Terminal/PowerShell

πŸŽ“ 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

  1. Add more questions: Ask about age, city, hobby, or favorite food
  2. Do math with the number: Multiply their number by 2 and show the result
  3. 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
Script #4

Simple Calculator Easy

πŸ“ Perform basic math operations on user-provided numbers

🎯
What You’ll Learn Arithmetic operations, number handling
⏱️
Estimated Time 12 minutes
πŸ”§
Tools Needed Terminal/PowerShell

πŸŽ“ 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

  1. Add modulo operation: Show remainder with $((num1 % num2))
  2. Add exponentiation: Calculate $((num1 ** num2)) (num1 to the power of num2)
  3. 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
Script #5

File Creator Easy

πŸ“ Create a new text file with user-provided content

🎯
What You’ll Learn File creation, writing to files
⏱️
Estimated Time 12 minutes
πŸ”§
Tools Needed Terminal/PowerShell

πŸŽ“ 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

  1. Add timestamp: Include creation date/time in the file
  2. Multiple lines: Allow user to enter multiple lines of content
  3. 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
Script #6

File Info Display Easy

πŸ“ Show detailed information about a file

🎯
What You’ll Learn File properties, conditionals
⏱️
Estimated Time 15 minutes
πŸ”§
Tools Needed Terminal/PowerShell

πŸŽ“ 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

  1. Show last lines: Display the last 5 lines instead of first
  2. Calculate MB/GB: Convert bytes to megabytes for large files
  3. 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

  1. Hello World – Basic output (5 min)
  2. Personal Greeting – Variables (8 min)
  3. Interactive Echo – User input (10 min)
  4. Simple Calculator – Math operations (12 min)
  5. File Creator – File writing (12 min)

🎯 Scripts 6-10: File Operations

  1. File Info Display – Reading properties (15 min)
  2. Multiple File Creator – Loops basics (18 min)
  3. File Organizer – Loops + conditions (20 min)
  4. Text Search – String searching (20 min)
  5. Backup Script – Copying with timestamps (25 min)

🎯 Scripts 11-15: Intermediate Skills

  1. Log File Cleaner – File deletion logic (25 min)
  2. Disk Space Monitor – System info (30 min)
  3. Process Lister – System processes (30 min)
  4. Password Generator – Random data (25 min)
  5. To-Do List Manager – File read/write/append (35 min)

🎯 Scripts 16-20: Advanced Integration

  1. User Account Creator – Input validation (40 min)
  2. System Health Report – Multiple checks (45 min)
  3. Automated Backup – Combining concepts (50 min)
  4. Log Analyzer – Text processing (50 min)
  5. 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
πŸ“– Script 1/20