Bash Workflow Automation
Project workbook ยท Path 76

Write a Bash script that summarizes a fixture directory, handles spaces and records failures without deleting source files.

The case

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.

EntryKindLines
notes one.txtfile2
notes-two.txtfile3
empty.txtfile0
archivedirectorynot counted
STAGE 1

Understand paths and streams

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.

Your task

Create the fixtures and inspect them without modifying their contents.

Required output

Fixture inventory

Record your result and evidence here or in a separate file.

Review gate

The spaced filename is handled as one path.

If the gate is not met

Print quoted arguments before adding processing logic.

STAGE 2

Build the file loop

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.

Your task

Write a loop that counts lines in top-level .txt files only.

Required output

Counting script

Record your result and evidence here or in a separate file.

Review gate

The empty file reports zero and the directory is skipped.

If the gate is not met

Test regular-file status inside the loop.

STAGE 3

Separate input and output

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.

Your task

Add argument checks and a separate report destination.

Required output

Rerunnable script

Record your result and evidence here or in a separate file.

Review gate

Two runs produce the same report and never count the report itself.

If the gate is not met

Compare the scan boundary with the output path.

STAGE 4

Test adverse inputs

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.

Your task

Run the supplied fixture checks and document the newline-filename limitation.

Required output

Test log

Record your result and evidence here or in a separate file.

Review gate

Missing input exits nonzero and original file hashes remain unchanged.

If the gate is not met

Make failure observable instead of printing a success message unconditionally.

STAGE 5

Explain operation and recovery

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.

Your task

Write usage examples and a recovery note for an invalid destination.

Required output

Runbook

Record your result and evidence here or in a separate file.

Review gate

The user can rerun after fixing the input without cleanup of source data.

If the gate is not met

List every created output file explicitly.

Final project

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.

Critical condition

Source files remain unchanged, paths with spaces work and failures return a nonzero exit status.

CriterionPointsEvidence
Evidence and correctness30Calculations, source use and results match the supplied case; limitations are honest.
Required artifacts30All five stage outputs and the capstone handoff are present and inspectable.
Reasoning and decisions20Choices, assumptions, alternatives and the case-specific critical condition are explained.
Reproducibility10A reviewer can follow the stated steps and distinguish expected from observed results.
Clear communication10Labels, 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.

Worked reference

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.

Boundaries

The script is scoped to local top-level text fixtures and newline-terminated lines; it is not a general backup or system administration tool.