forked from mikeplus64/fun.sh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fbash.sh
executable file
·100 lines (91 loc) · 1.33 KB
/
fbash.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
fold() {
funct="$@"
read acc
while read elem; do
acc="$(printf "%d$acc\n$elem" | $funct)"
done
echo $acc
}
list() {
for i in "$@"; do
echo "$i"
done
}
rlist() {
i="$#"
while [ $i -gt 0 ]; do
eval "f=\${$i}"
echo "$f "
i=$((i-1))
done
}
strcomp() {
if [ "$1" == "$2" ]; then
echo 1
else
echo 0
fi
}
filter() {
funct="$@"
resp=
while read elem; do
acc="$(printf "${elem}" | $funct)"
if [ $acc -eq 1 ]; then
resp+=" $elem"
fi
done
echo $resp
}
match() {
funct="$@"
while read elem; do
acc="$(printf "${elem}" | $funct)"
if [ $acc -eq 1 ]; then
echo $elem
break
fi
done
}
position() {
funct="$@"
pos=0
while read elem; do
acc="$(printf "${elem}" | $funct)"
if [ $acc -eq 1 ]; then
echo $pos
break
fi
pos=$((pos+1))
done
}
lambda() {
lam() {
unset last
for last; do
shift
if [[ $last = ":" ]]; then
echo "$@"
return
else
echo "read $last;"
fi
done
}
y="stdin"
for i in "$@"; do
if [[ $i = ":" ]]; then
y="args"
fi
done
if [[ "$y" = "stdin" ]]; then
read funct
eval $(lam "$@ : $funct")
else
eval $(lam "$@")
fi
unset y
unset i
unset funct
}