Write a Bash script that summarizes a fixture directory, handles spaces and records failures without deleting source files.
A fictional editor receives three text files: notes one.txt, notes-two.txt and empty.txt. The script must list each file and its line count into a new report. A fourth entry is a subdirectory and must be skipped. Source files must remain unchanged.
| Entry | Kind | Lines |
|---|---|---|
| notes one.txt | file | 2 |
| notes-two.txt | file | 3 |
| empty.txt | file | 0 |
| archive | directory | not counted |
A shell command receives arguments after expansion, so quoting determines whether a path with spaces remains one argument. Standard output is suitable for a report; standard error is suitable for diagnostics. Work inside a disposable case folder and identify the input and output boundaries before writing automation.
Create the fixtures and inspect them without modifying their contents.
Fixture inventory
Record your result and evidence here or in a separate file.
The spaced filename is handled as one path.
Print quoted arguments before adding processing logic.
Iterate over the expected files and check each is a regular file. Define behavior for an empty directory rather than allowing an unmatched pattern to become a fake filename. The supplied exercise uses Bash nullglob and a quoted loop. It intentionally avoids recursive deletion and does not follow arbitrary directory trees.
Write a loop that counts lines in top-level .txt files only.
Counting script
Record your result and evidence here or in a separate file.
The empty file reports zero and the directory is skipped.
Test regular-file status inside the loop.
A report written inside the scanned input can become a new input on the next run. Place it outside that directory or explicitly exclude it. Validate required arguments before processing. A temporary output followed by a rename can avoid presenting a partial report as complete when processing fails.
Add argument checks and a separate report destination.
Rerunnable script
Record your result and evidence here or in a separate file.
Two runs produce the same report and never count the report itself.
Compare the scan boundary with the output path.
Test the behaviors most likely to break a shell script: spaces, an empty directory, a missing input directory and a destination collision. Record exit status as well as text output. The reference scope excludes filenames containing newlines because the CSV output contract cannot represent them safely without additional escaping.
Run the supplied fixture checks and document the newline-filename limitation.
Test log
Record your result and evidence here or in a separate file.
Missing input exits nonzero and original file hashes remain unchanged.
Make failure observable instead of printing a success message unconditionally.
A small runbook should say what the script reads, what it writes and how a user knows it succeeded. Include dependencies and the expected output. Avoid broad permission changes or system-wide configuration for a local report. Keep the command easy to reproduce from a clean fixture directory.
Write usage examples and a recovery note for an invalid destination.
Runbook
Record your result and evidence here or in a separate file.
The user can rerun after fixing the input without cleanup of source data.
List every created output file explicitly.
Deliver the Bash script, fixtures, expected report, hash-preservation check and runbook. Add a fourth file with spaces in its name and verify the report updates correctly.
Source files remain unchanged, paths with spaces work and failures return a nonzero exit status.
| Criterion | Points | Evidence |
|---|---|---|
| Evidence and correctness | 30 | Calculations, source use and results match the supplied case; limitations are honest. |
| Required artifacts | 30 | All five stage outputs and the capstone handoff are present and inspectable. |
| Reasoning and decisions | 20 | Choices, assumptions, alternatives and the case-specific critical condition are explained. |
| Reproducibility | 10 | A reviewer can follow the stated steps and distinguish expected from observed results. |
| Clear communication | 10 | Labels, units, structure and evidence references make the work easy to review. |
Score at least 80/100, supply every required artifact, and satisfy the path-specific critical condition. Rework missing evidence before marking complete.
The three regular text files contain 2, 3 and 0 newline-terminated lines, totaling 5. wc counts newline characters, so an unterminated last line needs a separate policy. The fixtures intentionally end their nonempty lines with newlines.
The script is scoped to local top-level text fixtures and newline-terminated lines; it is not a general backup or system administration tool.