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.
- Create
fruitswith aforloop overapples pears oranges mangoes, printing a sentence with each value. Save, set the intended mode, verify withls -l, run as the worksheet specifies, and record output. - Create
namelistthat loops overTom John Ericand prints each name. Save, make executable as directed, verify permissions and run. - Create a loop over
one two three four fivethat 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. - Write a loop producing one sentence each for Mets, Yankees, Braves, and Astros. Mark
for, variable,inlist,do, body,done. - Write a loop that runs
who,ls, andpwdby invoking each list value. Record actual output and explain whywho/lsmay vary. - Explain how the list determines iterations; predict number and order before each run.
- 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?]