Practice & Assessment
Test your understanding of Control Flow and Logic
Multiple Choice Questions
5What is the difference between `[ ]` and `[[ ]]` in Bash conditionals?
What is the correct way to read a file line by line in Bash, preserving whitespace?
In a Bash `case` statement, what does `;;` do?
How do you access ALL elements of a Bash array while preserving elements that contain spaces?
What variable controls the prompt string displayed by Bash's `select` statement?
Coding Challenges
1Log File Analyzer
Write `analyze_logs.sh` that accepts a log file path as `$1` and a severity level (ERROR, WARN, INFO) as `$2`. Use a `while` loop to read the file line by line. Count occurrences of the given severity level and print matching lines prefixed with their line number. At the end, print a summary: `Found N [SEVERITY] entries`. Validate that the file exists and is readable; validate that the severity is one of the three valid values using a `case` statement. Exit 1 with a message to stderr on invalid input. Input: path to a log file, severity string. Output: numbered matching lines, then summary line. Time estimate: 20-25 minutes.
Mini Project
Interactive Environment Setup Wizard
Build `setup-wizard.sh` that interactively configures a project environment. Use `select` to let the user choose a project type (web, api, cli, data). Use `read` with validation to collect: project name (must be alphanumeric plus hyphens), target directory, and git remote URL (optional). Use `case` on project type to create type-specific directory structures with a `for` loop. Store all collected config in a Bash associative array and write it to `.env` format at the end. Use arrays to track created directories and print a summary. Include input validation with clear error messages. Use `set -euo pipefail` and `trap` cleanup.
