3.2 KiB
📘 Week 1 · Day 5 — Bash Exercises
This README documents all exercises for Week 1 Day 5, focused on Bash scripting for Linux system administration and security workflows.
The exercises mirror the logic implemented previously in C, Python, SQL, and PowerShell, reinforcing algorithmic thinking while introducing Unix shell syntax, conditionals, loops, and defensive scripting.
🎯 Learning Objectives
By completing today’s exercises, you will:
- Use Bash variables and user input (
read) - Apply conditional logic with
if / elif / else - Loop over strings and arrays using
for - Perform character validation using regex
- Implement secure input validation logic
- Analyze algorithm runtime and scalability
- Gain confidence writing Linux automation scripts
🛠 Exercises Overview
🧪 Exercise 1 — Even / Odd Number Checker
Task:
- Prompt the user for a number
- Determine whether the number is
EvenorOdd
Concepts practiced:
- Numeric input handling
- Arithmetic expressions:
(( )) - Conditional branching
🧪 Exercise 2 — Count Letters in a String
Task:
- Prompt the user for a string
- Count letters only (
A–Z,a–z) - Ignore spaces, digits, and special characters
Concepts practiced:
- Looping over string characters
- Regex matching using
[[ =~ ]] - Counter variables
🧪 Exercise 3 — Username Validator (Single User)
Task: Validate a username using these rules:
- Length ≤ 20 characters
- Starts with a letter
- Contains letters only
- No digits
- No spaces
Output:
AcceptedorRefused
Concepts practiced:
- Defensive input validation
- Early exit with
break - String length checking
- First-character validation
🧪 Exercise 4 — Validate Multiple Usernames
Input:
users=("admin" "root1" "John_Doe" "Alice" "Bob42")
Task:
- Loop through each username
- Apply the same validation rules as Exercise 3
- Print whether each username is valid or invalid
Concepts practiced:
- Array iteration
- Nested loops
- Reusable validation logic
🧪 Exercise 5 — Algorithm Analysis (Written)
Task: Explain what happens to execution time if the number of usernames doubles.
Use:
n= number of usernamesm= average username length
Expected result:
T(n, m) = n × m
T(2n, m) = 2 × n × m
Big-O: O(n·m)
🔐 Security & Sysadmin Perspective
These exercises reflect real-world Bash usage in:
- Linux user management
- Input validation scripts
- SSH and access control automation
- Log parsing and monitoring
- Security audits and recon scripts
Strong validation and predictable runtime are critical for secure and reliable system scripts.
✅ Completion Criteria
Day 5 is complete when:
- Exercises 1–4 run correctly in Bash
- Exercise 5 clearly explains runtime scaling
- Scripts follow safe Bash practices (
[[ ]], quoting, defensive checks)
🔜 Next Step
After Day 5, Week 1 concludes.
Upcoming:
- Week 2: Data Structures (arrays, maps, sets)
- Stronger algorithm focus
- More security-oriented scripting examples
📌 This README serves as a reference and checklist for Week 1 Day 5 Bash exercises.