Open in TheBrain

Practice Lab 10.4

Practice Lab 10.4 — for Loops: Lists, Output, Commands

Name: Date:

Instructions

Use Bash and the vi editor as directed. Complete the entire worksheet, recording predictions, commands, output, and explanations. Keep scripts in a disposable practice folder.

  1. Build and run fruits: iterate over four fruit values and print a sentence for each. Record the list, variable, body, and output.
  2. Build namelist: loop over three names and print each. Set mode as assigned and verify with ls -l before running.
  3. Build a word-list loop using one two three four five. Explain whether it is a numeric counter and why.
  4. Write the loop that prints the requested baseball-team sentence for Mets, Yankees, Braves, Astros; identify each syntax keyword.
  5. Write a loop that executes who, ls, pwd. Predict each result type, then run and explain variable output.
  6. Compare iteration counts in all loops. Add/remove one item from a list and record how output changes.
  7. Explain vi save/exit, permission adjustment, verification, and script invocation used.

Reflection: What part of the for syntax separates the item list from the repeated body?