-
Notifications
You must be signed in to change notification settings - Fork 10
/
demo.sh
executable file
·58 lines (48 loc) · 1.1 KB
/
demo.sh
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
51
52
53
54
55
56
57
58
#!/bin/bash
#
# Problems:
# - Shell and awk should be combined
# - Shell needs escaping. If they weren't combined, they BOTH would need
# escaping.
#
# Usage:
# ./demo.sh <function name>
set -o nounset
set -o pipefail
set -o errexit
# Point-free function
hist() {
sort | uniq -c | sort -r -n
}
hist-demo() {
{ echo foo; echo bar; echo foo; } | hist
}
# NOTE: not safe
awk-html-rows() {
awk '
BEGIN { print "<tr> <td>Count</td> <td>Name</td> </tr>"}
{ print "<tr> <td>" $1 "</td> <td>" $2 "</td> </tr>"}
'
}
hist-pipeline-demo() {
{ echo foo; echo bar; echo foo; } | hist | awk-html-rows
}
shell-html-rows() {
echo "<tr> <td>Count</td> <td>Name</td> </tr>"
while read count name; do
echo "<tr> <td>$count</td> <td>$name</td> </tr>"
done
}
while-pipeline-demo() {
{ echo foo; echo bar; echo foo; } | hist | shell-html-rows
}
inline-demo() {
{ echo foo; echo bar; echo foo; } |
sort | uniq -c | sort -r -n |
{ echo "<tr> <td>Count</td> <td>Name</td> </tr>";
while read count name; do
echo "<tr> <td>$count</td> <td>$name</td> </tr>"
done
}
}
"$@"