Loops
Do the same thing to every file, every line, or until something is true.
Updated
Repeating
- For Every File: for Loops (Apprentice): A for loop runs the same commands once for every word, number or file in a list, so renaming 12 files or 200 takes one line, with ${f%.tmp} cutting the old ending off each name.
- Line by Line: while read (Journeyman): while IFS= read -r line reads a file one whole line at a time, spaces and backslashes kept, and while and until repeat commands for as long as a condition is true, or until it becomes true.
- Stopping Early: break, continue and Counters (Apprentice): A counter or running total is a variable a loop adds to each time round with $(( )); continue skips the rest of one pass and goes on with the next item, and break leaves the loop early.
Exercise: Rename the Telemetry
- Exercise: Rename the Telemetry (Apprentice): Write two small tools for Mission Control, a script that renames every .tmp file in a folder and one that pulls the warnings out of a flight log, then run them on the real files and let a check script tell you what's done.