Open in TheBrain

Practice Lab 10.1

Practice Lab 10.1 — Complete for Loop Practice

Name: Date:

Instructions fruits

Use Bash in an approved practice directory. Write scripts in vi as the course directs. Before running, trace each loop variable and list; then record output and explain. Use straight quotes and verify filenames/modes.

  1. Create fruits with a for loop over apples pears oranges mangoes, printing a sentence with each value. Save, set the intended mode, verify with ls -l, run as the worksheet specifies, and record output.
  2. Create namelist that loops over Tom John Eric and prints each name. Save, make executable as directed, verify permissions and run.
  3. Create a loop over one two three four five that prints a message containing the current value. Is it a numeric counter? Explain the distinction between iterating over number words and updating a numeric variable.
  4. Write a loop producing one sentence each for Mets, Yankees, Braves, and Astros. Mark for, variable, in list, do, body, done.
  5. Write a loop that runs who, ls, and pwd by invoking each list value. Record actual output and explain why who/ls may vary.
  6. Explain how the list determines iterations; predict number and order before each run.
  7. For every script, explain how you saved, set permissions, invoked, and verified it.

Reflection: Which loop traced most clearly from list item to command output?

Page Content Map

flowchart TD
    A[Practice Lab 10.1: for-loop practice] --> B[Instructions]
    B --> B1[Use Bash in approved directory]
    B --> B2[Write scripts in vi]
    B --> B3[Trace variables and lists before running]
    B --> B4[Record output and explain]
    B --> B5[Use straight quotes; verify filenames and modes]
    A --> C[Exercises]
    C --> C1[fruits: iterate apples, pears, oranges, mangoes]
    C1 --> C1a[Save, set mode, verify with ls -l, run, record output]
    C --> C2[namelist: iterate Tom, John, Eric]
    C2 --> C2a[Save, make executable, verify permissions, run]
    C --> C3[Iterate one through five; distinguish list iteration from a numeric counter]
    C --> C4[Write team-sentence loop; identify for, variable, in-list, do, body, done]
    C --> C5[Run who, ls, pwd from list values; record and explain variable output]
    C --> C6[Explain how list determines iteration count and order]
    C --> C7[For each script: explain saving, permissions, invocation, and verification]
    A --> D[Reflection]
    D --> D1[Which loop was clearest to trace from list item to command output?]