Skip to content

Commit c2c2fb4

Browse files
authored
Merge pull request #290 from bkmgit/patch-5
Use clearer variable name
2 parents d0c87fd + 76a7936 commit c2c2fb4

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

episodes/04-loops.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ We have called the variable in this loop `filename` in order to make its purpose
101101
Complete the blanks in the for loop below to print the name, first line, and last line of each text file in the current directory.
102102

103103
```bash
104-
___ file in *.txt
104+
___ filename in *.txt
105105
__
106-
echo "_file"
106+
echo "_filename"
107107
head -n 1 _______
108108
____ __ _ _______
109109
____
@@ -114,11 +114,11 @@ ____
114114
## Solution
115115

116116
```bash
117-
for file in *.txt
117+
for filename in *.txt
118118
do
119-
echo "$file"
120-
head -n 1 "$file"
121-
tail -n 1 "$file"
119+
echo "$filename"
120+
head -n 1 "$filename"
121+
tail -n 1 "$filename"
122122
done
123123
```
124124

@@ -141,11 +141,11 @@ Alternatively, rather than running the loop above on the command line, you can s
141141
# This script loops through .txt files, returns the file name,
142142
# first line, and last line of the file
143143
144-
for file in *.txt
144+
for filename in *.txt
145145
do
146-
echo "$file"
147-
head -n 1 "$file"
148-
tail -n 1 "$file"
146+
echo "$filename"
147+
head -n 1 "$filename"
148+
tail -n 1 "$filename"
149149
done
150150
```
151151

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
2-
# This script loops through .txt files, returns the
3-
# file name, first line, and last line of the file
2+
# This script loops through .txt files, returns the file name,
3+
# first line, and last line of the file
44

5-
for file in *.txt
5+
for filename in *.txt
66
do
7-
echo "$file"
8-
head -n 1 "$file"
9-
tail -n 1 "$file"
7+
echo "$filename"
8+
head -n 1 "$filename"
9+
tail -n 1 "$filename"
1010
done

0 commit comments

Comments
 (0)