Skip to content

Commit 94a61f9

Browse files
authored
Update 04-loops.md
In teaching today, our group of Library Carpentry instructors all agreed that we would prefer to use .txt instead of .doc files because we'd like to encourage use of non-proprietary files.
1 parent 47a56fa commit 94a61f9

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

_episodes/04-loops.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ keypoints:
1717
**Loops** are key to productivity improvements through automation as they allow us to execute
1818
commands repetitively. Similar to wildcards and tab completion, using loops also reduces the
1919
amount of typing (and typing mistakes).
20-
Suppose we have several hundred document files named `project_1825.doc`, `project_1863.doc`, `XML_project.doc`and so on.
20+
Suppose we have several hundred document files named `project_1825.txt`, `project_1863.txt`, `XML_project.txt` and so on.
2121
We would like to change these files, but also save a version of the original files, naming the copies
22-
`backup_project_1825.doc` and so on.
22+
`backup_project_1825.txt` and so on.
2323

2424
We can use a **loop** to do that.
2525
Here's a simple example that creates a backup copy of four text files in turn.
2626

2727
Let's first create those files:
2828

2929
~~~
30-
$ touch a.doc b.doc c.doc d.doc
30+
$ touch a.txt b.txt c.txt d.txt
3131
~~~
3232
This will create four empty files with those names. It is easy to use the shell to create a batch of files in one go.
3333

@@ -45,7 +45,7 @@ We can apply this to our example like this:
4545

4646

4747
~~~
48-
$ for filename in *.doc
48+
$ for filename in *.txt
4949
> do
5050
> echo "$filename"
5151
> cp "$filename" backup_"$filename"
@@ -54,10 +54,10 @@ $ for filename in *.doc
5454
{: .bash}
5555

5656
~~~
57-
a.doc
58-
b.doc
59-
c.doc
60-
d.doc
57+
a.txt
58+
b.txt
59+
c.txt
60+
d.txt
6161
~~~
6262
{: .output}
6363

@@ -84,14 +84,14 @@ rather than treat it as text or an external command.
8484
> enter your loop variable (such as in [episode 5]({{ page.root }}/05-counting-mining/index.html#using-a-loop-to-count-words)).
8585
{: .callout}
8686

87-
In this example, the list is four filenames: 'a.doc', 'b.doc', 'c.doc', and 'd.doc'
87+
In this example, the list is four filenames: 'a.txt', 'b.txt', 'c.txt', and 'd.txt'
8888
Each time the loop iterates, it will assign a file name to the variable `filename`
8989
and run the `cp` command.
9090
The first time through the loop,
91-
`$filename` is `a.doc`.
92-
The interpreter prints the filename to the screen and then runs the command `cp` on `a.doc`, (because we asked it to echo each filename as it works its way through the loop).
91+
`$filename` is `a.txt`.
92+
The interpreter prints the filename to the screen and then runs the command `cp` on `a.txt`, (because we asked it to echo each filename as it works its way through the loop).
9393
For the second iteration, `$filename` becomes
94-
`b.doc`. This time, the shell prints the filename `b.doc` to the screen, then runs `cp` on `b.doc`. The loop performs the same operations for `c.doc` and then for `d.doc` and then, since
94+
`b.txt`. This time, the shell prints the filename `b.txt` to the screen, then runs `cp` on `b.txt`. The loop performs the same operations for `c.txt` and then for `d.txt` and then, since
9595
the list only included these four items, the shell exits the `for` loop at that point.
9696

9797
> ## Follow the Prompt

0 commit comments

Comments
 (0)