Skip to main content

Development Environment: Guided Lab

Planning allowance: 60–90 minutes, already inside Module 2. Use a Unix-style shell as explained in the beginner route. No Python or prior general-purpose programming is required.

Predict, then create the fixture​

Create a new disposable folder named tooling-lab somewhere you can find again. If that name already exists, choose a new empty parent; do not overwrite an earlier attempt. Run the following in that parent folder:

mkdir tooling-lab
cd tooling-lab
printf 'alpha\nbeta\ngamma\n' > 'sample data.txt'
printf 'wc -l < "$1"\n' > count-lines.sh

Open count-lines.sh in your editor. It must contain exactly:

wc -l < "$1"

sh count-lines.sh ... asks a shell to run the commands in the file; this route does not require executable permission or a shebang. $1 means its first argument. The quotes keep the whole path together. < opens that path as standard input; wc -l counts newline characters in that input. The fixture contains three newline-terminated lines. This tiny script assumes exactly one input path; it is not a general file-processing application.

Run from two locations​

Predict each result before executing it:

sh count-lines.sh 'sample data.txt'
printf 'status=%s\n' "$?"
cd ..
sh tooling-lab/count-lines.sh 'tooling-lab/sample data.txt'
printf 'status=%s\n' "$?"

Both successful runs print the number 3 (possibly padded with spaces) and status 0. The data path is relative to the caller's working directory, not automatically to the script. Explain why both the script path and input path change in the second run.

Keep failure visible​

Still in the parent directory, run:

sh tooling-lab/count-lines.sh 'tooling-lab/missing.txt' > tooling-lab/out.txt 2> tooling-lab/err.txt
printf 'status=%s\n' "$?"
cat tooling-lab/out.txt
cat tooling-lab/err.txt

The status must be nonzero, out.txt empty, and err.txt must identify the failed file access. Exact status and error wording depend on the shell. Inspect status immediately: the next command replaces $?. Since input redirection fails, wc never receives the missing file as input. Do not turn this into a false “zero lines” success.

Now deliberately omit quotes around sample data.txt in the original invocation. Predict which word becomes $1; preserve the observed failure, then repair the invocation. Use only this disposable fixture.

Fresh transfer and acceptance​

Create a differently named text file with four newline-terminated lines in a different subfolder, then run the same script from the parent. Predict the number and status without viewing the earlier command. Also create a file containing alpha with no final newline using printf 'alpha'. Predict what wc -l counts, compare with your editor's displayed line, and state the limitation.

Keep the two-location transcript, separated error/output files, fresh transfer, editor save/reopen evidence and setup notes (OS, shell, available utilities and exact commands). Recreate the fixture in a fresh directory using the checklist. No result depends on an unsaved editor buffer. A successful demonstration is tooling evidence, not a claim of broader programming proficiency.

Use the worked examples for diagnosis. The command's newline behavior can also be checked in your installed man wc documentation.