Practice Lab 10.9
Practice Lab 10.9 — Complete Loop Construction Worksheet
Name: Date:
Instructions
Use Bash and vi; keep all scripts in a practice directory. Write, inspect, set permissions, run, and explain each program. Predict first.
- Build a fruit-list script that prints a line for each of four values; record the list and output.
- Build a name-list script with three different names; record command, permission state, and output.
- Build a number-word loop and explain the difference between iteration over labels and arithmetic counting.
- Write the four-team output loop from the lab, preserving exact sentence structure. Label
for, loop variable,in,do, body, anddone. - Write a loop that runs
who,ls,pwd. Explain how$loopis used to execute each command and record actual results. - Create a loop over a list with one repeated item; predict and count repetitions.
- Explain how changing list order changes output order, and how changing list length changes executions.
- Record how you saved the scripts, verified permissions and filenames, and invoked them.
Reflection: How can you tell whether a loop body prints a command name or runs the command itself?