Skip to content

Commit 273962a

Browse files
authored
Merge pull request #259 from bkmgit/patch-2
Add quotes to variables in script
2 parents 0f8ff7b + b1bfb02 commit 273962a

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

episodes/04-loops.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,13 @@ Alternatively, rather than running the loop above on the command line, you can s
138138

139139
```
140140
#!/bin/bash
141-
# This script loops through .txt files, returns the file name, first line, and last line of the file
141+
# This script loops through .txt files, returns the file name,
142+
# first line, and last line of the file
142143
for file in *.txt
143144
do
144-
echo $file
145-
head -n 1 $file
146-
tail -n 1 $file
145+
echo "$file"
146+
head -n 1 "$file"
147+
tail -n 1 "$file"
147148
done
148149
```
149150

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +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
24

3-
for filename in *.txt
5+
for file in *.txt
46
do
5-
echo $filename
6-
head -n 5 $filename
7-
tail -n 5 $filename
8-
done
7+
echo "$file"
8+
head -n 1 "$file"
9+
tail -n 1 "$file"
10+
done

0 commit comments

Comments
 (0)