Skip to main content

Development Environment: Worked Examples

Predict before executing these examples in the guided lab's disposable folder. They use shell tools already taught in Cluster 1.

Same relative path, different starting folder​

Inside tooling-lab, sh count-lines.sh 'sample data.txt' works. In its parent, the script is tooling-lab/count-lines.sh and the input is tooling-lab/sample data.txt. Fixing only the script path does not repair the input path. Inspect pwd and the actual folder before changing the script or reinstalling a tool.

Transfer: put the input in a subfolder and explain which argument must change when you move to the parent. The script does not change the caller's working directory.

A filename with spaces​

Inspect argument boundaries directly, without writing a program:

printf '<%s>\n' sample data.txt
printf '<%s>\n' 'sample data.txt'

The first prints two bracketed arguments; the second prints one. The quotes guide shell parsing and are not part of the filename. Later quoting of $1 cannot recover an argument that was already split in the original invocation.

A plausible number can hide failure​

For this controlled observation, use Bash without enabling pipefail:

bash --noprofile --norc
cat 'missing.txt' | wc -l
printf 'status=%s\n' "$?"
exit

In a new disposable directory with no missing.txt, cat reports an error but wc receives empty input and prints 0. The default pipeline status comes from its last command, so it can be 0 despite the earlier failure. The guided lab uses input redirection to keep missing-file failure visible. More complex scripts need explicit failure handling; a zero count alone is not proof that an input was read.

Configuration file versus live shell state​

Deleting an alias definition from a file does not erase the alias from an already-running shell. Reloading an empty file executes no removal command. Use unalias to remove the live alias, or start a fresh isolated shell that never defined it. The configuration lab demonstrates both states without editing your personal startup files.

Keep one failed prediction or deliberately seeded failure with its repair; label seeded failures honestly. The guided lab supplies the transfer assessment. Official background: Missing Semester arguments, streams and return codes.