end of day 5 week 1

This commit is contained in:
2026-01-22 21:36:02 +01:00
parent 82b79336ea
commit 3e23329086
8 changed files with 529 additions and 0 deletions

158
week 1/day 5/readme.md Normal file
View File

@@ -0,0 +1,158 @@
# 📘 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 todays 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 `Even` or `Odd`
**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** (`AZ`, `az`)
* 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:**
* `Accepted` or `Refused`
**Concepts practiced:**
* Defensive input validation
* Early exit with `break`
* String length checking
* First-character validation
---
### 🧪 Exercise 4 — Validate Multiple Usernames
**Input:**
```bash
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 usernames
* `m` = 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 14 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.*