Open in TheBrain

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.

  1. Build a fruit-list script that prints a line for each of four values; record the list and output.
  2. Build a name-list script with three different names; record command, permission state, and output.
  3. Build a number-word loop and explain the difference between iteration over labels and arithmetic counting.
  4. Write the four-team output loop from the lab, preserving exact sentence structure. Label for, loop variable, in, do, body, and done.
  5. Write a loop that runs who, ls, pwd. Explain how $loop is used to execute each command and record actual results.
  6. Create a loop over a list with one repeated item; predict and count repetitions.
  7. Explain how changing list order changes output order, and how changing list length changes executions.
  8. 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?