Open in TheBrain

Practice Lab 10.3

Practice Lab 10.3 — Complete Bash for Loop Lab

Name: Date:

Instructions

Work in a practice directory using the assigned shell. Type scripts in vi, save, verify, and run. Trace values first; record output and explain keywords.

  1. Write fruits loop over apples pears oranges mangoes, printing a descriptive message for each. Verify filename/mode and run.
  2. Write namelist loop over three different first names and echo each. Save, set executable mode as requested, verify and run.
  3. Loop over words one two three four five, include the current value in output. Explain “counter” versus list iteration.
  4. Create the baseball-team sentence loop for Mets, Yankees, Braves, Astros. Underline/identify for, variable, in, list, do, body, done.
  5. Build command loop running who, ls, pwd; invoke loop value as a command, record real output.
  6. For each script, predict iteration count and output order. Add one extra list value to one script and explain the effect.
  7. Describe how you save, verify, set permissions, and run each script; note differences between sourcing and executing if relevant.

Reflection: Which command-loop output changed because of system state rather than loop syntax?