forked from RahafB/bash_basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08-count.sh
More file actions
33 lines (27 loc) · 733 Bytes
/
08-count.sh
File metadata and controls
33 lines (27 loc) · 733 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
#!/bin/sh
# the for-loop goes over a list of words
# it uses the do-done keywords just like the while loop
# count how many lines each shell script contains
for file in *.sh; do
# backticks are used for command substitution
# the command in the backticks are executed and
# the output is returned back
lines=`wc $file | tr -s ' ' | cut -f2 -d' '`
echo "$file has $lines lines"
done
# exercise: Loop over some type of files and use the
# "grep" UNIX command to find snippets of strings in them.
echo "Counting finished!"
# Backward counting
for i in {10..1}
do
echo "Backward: $i"
done
# New feature: count even
for i in {1..10}
do
if (( i % 2 == 0 ))
then
echo "Even: $i"
fi
done