Skip to content

Commit 39916ef

Browse files
Small fixes to bash loops (bobbyiliev#100)
1 parent 12dba63 commit 39916ef

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

ebook/en/content/011-bash-loops.md

+11-12
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ done
2929
A quick rundown of the example:
3030

3131
* First, we specify a list of users and store the value in a variable called `$users`.
32-
* After that, we start our `for` loop with the `for` keyword
32+
* After that, we start our `for` loop with the `for` keyword.
3333
* Then we define a new variable which would represent each item from the list that we give. In our case, we define a variable called `user`, which would represent each user from the `$users` variable.
34-
* Then we specify the `in` keyword followed by our list that we will loop through
35-
* On the next line, we use the `do` keyword, which indicates what we will do for each iteration of the loop
36-
* Then we specify the commands that we want to run
37-
* Finally, we close the loop with the `done` keyword
34+
* Then we specify the `in` keyword followed by our list that we will loop through.
35+
* On the next line, we use the `do` keyword, which indicates what we will do for each iteration of the loop.
36+
* Then we specify the commands that we want to run.
37+
* Finally, we close the loop with the `done` keyword.
3838

3939
You can also use `for` to process a series of numbers. For example here is one way to loop through from 1 to 10:
4040

@@ -54,7 +54,7 @@ The structure of a while loop is quite similar to the `for` loop:
5454
```bash
5555
while [ your_condition ]
5656
do
57-
your_conditions
57+
your_commands
5858
done
5959
```
6060

@@ -137,16 +137,15 @@ for i in 1 2 3 4 5
137137
do
138138
if [ $i –eq 2 ]
139139
then
140-
echo skipping number 2
140+
echo "skipping number 2"
141141
continue
142142
fi
143-
echo “I is equal to $i
143+
echo "i is equal to $i"
144144
done
145145
```
146146

147147
We can also use continue command in similar way to break command for controlling multiple loops.
148148

149-
150149
* `break` tells your bash script to end the loop straight away.
151150

152151
The syntax of the break statement takes the following form:
@@ -170,7 +169,7 @@ do
170169
fi
171170
((num++))
172171
done
173-
echo Loop completed
172+
echo "Loop completed"
174173
```
175174

176175
We can also use break command with multiple loops. If we want to exit out of current working loop whether inner or outer loop, we simply use break but if we are in inner loop & want to exit out of outer loop, we use break 2.
@@ -182,14 +181,14 @@ Example:
182181

183182
for (( a = 1; a < 10; a++ ))
184183
do
185-
echo outer loop: $a
184+
echo "outer loop: $a"
186185
for (( b = 1; b < 100; b++ ))
187186
do
188187
if [ $b –gt 5 ]
189188
then
190189
break 2
191190
fi
192-
echo Inner loop: $b
191+
echo "Inner loop: $b "
193192
done
194193
done
195194
```

0 commit comments

Comments
 (0)