-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfork.sh
executable file
·87 lines (81 loc) · 1.17 KB
/
fork.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
#!./socketpair /opt/local/bin/bash
. ../bash/upvars.inc.sh
_val=0
output() {
count=$1
echo $count
_val="$count"
}
output_upvar() {
count=$1
local "$2" && upvar $2 "$1"
}
output_eval() {
count=$1
eval "$2=$1"
}
# local "$1" && upvar $1 "value(s)"
pipevar() {
read
local "$1" && upvar $1 "$REPLY"
}
method() {
val=0;
for (( i=0 ; i<2000; i++ )); do
case $1 in
a )
val=$( output $i )
;;
b )
output $i > /tmp/$$
pipevar val < /tmp/$$
# rm /tmp/$$
;;
c )
output $i | pipevar val
;;
d )
pipevar val < <( output $i )
;;
e )
fd=<( output $i )
pipevar val < $fd
;;
f )
if [ ! -z "$DUP1" ]; then
output $i >& $DUP1
pipevar val <& $DUP2
fi
;;
g )
output $i
val="$_val"
;;
h )
if [ ! -z "$DUP1" ]; then
output $i >& $DUP1
read -u $DUP2 val
fi
;;
i )
output_upvar $i val
;;
j )
output_eval $i val
;;
k )
__=${val:0:1}
;;
l )
__=${val[0]}
;;
esac
done > /dev/null
echo -n "$val "
}
declare -a methods
methods=( a b c d e f g h i j k l )
for m in ${methods[@]}; do
echo -n "method $m: "
time method $m
done