Practice Lab 10.16
Practice Lab 10.16 — Expanded for Loop Practice
Name: Date:
Instructions
Use Bash and vi in a practice directory. Every task is part of a complete Lab 10 review. Trace list values before running, then record code, mode, output, and explanation.
- Create
fruitsto loop overapples pears oranges mangoes, printing each value in a sentence. Save, inspect, set the assigned permissions, run. - Create
namelistover three names and print one per pass. Verify filename and mode, then run. - Loop over
one two three four five; explain why this iterates through words rather than numerically updating a counter. - Write the four-team sentence loop from the source lab and mark the loop variable/list/keywords.
- Write a command loop to run
who,ls, andpwd; explain variable command execution and note output variation. - Add a fifth fruit and a repeated name to custom lists. Predict and record iteration count/order; explain how duplicates behave.
- Explain how the list, loop variable, and body interact; summarize saving and executing scripts.
Reflection: How do changes in list content affect the loop without changing the loop body?