Language: bash
Difficulty: intermediate
Create a portable Bash script (file-ext-summary.sh) that counts regular files grouped by file extension in a target directory and prints a sorted summary. Requirements:
- Usage: ./file-ext-summary.sh [-r] [directory]
- If directory omitted, default to current working directory.
- -r enables recursive search.
- -h|--help prints usage and exits.
- Treat filenames with spaces and special characters correctly.
- Group extensions case-insensitively (e.g., .MD and .md count together).
- Files without an extension should be counted under the label "no_extension".
- Output should be sorted by descending count, one entry per line: COUNT EXTENSION (e.g. "42 md").
- Exit with non-zero on error and print helpful errors.
Hints: use find -print0 and a while loop (IFS= read -r -d '' file); use parameter expansion or awk to extract extensions; aggregate with awk/sort/uniq -c.
solution.sh
Strong solution with solid logic, but hidden file duplication bug in fallback path when -maxdepth unsupported.
# Clone the repository
git clone <this-repo-url>
cd <repo-name>
# Run the solution (adjust based on language)
# TypeScript: npx ts-node solution.ts
# Python: python solution.py
# Java: javac Solution.java && java SolutionExported from Flight School using GitHub Copilot SDK