for runs the same lines one time for each item in a list. A variable holds the item of each turn:
learner@reef:~$ cat days.sh
#!/bin/bash
for day in mon tue wed; do ← day is mon, then tue, then wed
echo "open on $day" ← the lines to repeat
done ← the end of them
learner@reef:~$ bash days.sh
open on mon
open on tue
open on wed| List | Gives |
|---|---|
mon tue wed | The words, as you typed them |
~/menus/*.txt | Each path that matches the wildcard |
Write the variable in double quotes, "$f", so that a path with a space stays one argument.
-
Write
~/errors-per-log.sh, with#!/bin/bashon top. For each.logfile in~/logs, it writes the path, a colon, and how manyERRORlines the file has. One name has a space. Make it runnable withchmod u+x, and run it:textlearner@reef:~$ ./errors-per-log.sh /home/learner/logs/card reader.log: 2 /home/learner/logs/door.log: 0 /home/learner/logs/fridge.log: 1 /home/learner/logs/register.log: 2 -
Loop over a wildcard, not a list of names: a log added tomorrow must get its line too.
Objectives
- One line for each
.logfile in~/logs. - A log added tomorrow gets its line too.