-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path4-Loops.sh
More file actions
50 lines (44 loc) · 859 Bytes
/
4-Loops.sh
File metadata and controls
50 lines (44 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
#Bash Tutorial 4: Loops
#Written by QuidsUp
#Use with Youtube Video: http://youtu.be/sCmqBkz1yYY
echo "List all files of a specific type in a folder"
for i in $(ls ~/Videos/ | grep .mp4); do
echo $i
done
echo
echo "Numerical count version of a For loop"
for i in {1..5}; do
echo "Pass:" $i
done
echo
echo "While Loop"
Count=0
while [ $Count -lt 5 ]; do
echo "Count is" $Count
let Count=Count+1
done
echo
echo "Until Loop"
Count=0
until [ $Count -gt 5 ]; do
echo "Count is" $Count
let Count=Count+1
done
echo
echo "Infinite loop until 'break' statement"
while [ 1 ]; do
echo -n "Do you want to leave the loop yet?"
read Choice
if [[ $Choice == "y" ]]; then
break
fi
done
Loop=1
while [ $Loop -eq 1 ]; do
echo -n "Do you want to leave the loop yet?"
read Choice
if [[ $Choice == "y" ]]; then
Loop=0
fi
done