-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_func_callout
executable file
·62 lines (48 loc) · 1.36 KB
/
test_func_callout
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
#!/usr/bin/env bash
source mod_common
bi_enable
run_test()
{
# variables external to callback function from which
# values will be snagged.
local -i ndx=0;
local -a values=(
first
second
third
fourth
fifth
sixth
)
nested_function()
{
local -n nf_var="$1"
local -n valarr="${2:-values}"
if [ $ndx -lt "${#valarr[*]}" ]; then
nf_var="${valarr[$ndx]}"
(( ++ndx ))
return 0
fi
return 1
}
echo "About to call ${B}func_callout${X} with a callback providing"
echo "a set of english number names."
echo
func_callout "nested_function"
echo
echo "About to call ${B}func_callout${X} with a second parameter"
echo "which will be transferred to the callback function to"
echo "override the default array source of values."
ndx=0
local -a altarray=( un dos tres quatre cinq six )
func_callout "nested_function" "altarray"
}
cat <<EOF
This tests a technique for a Bash builtin function to poll for
information from a shell script function.
The builtin function ${B}func_callout${X} will be called with
the name of a script function that the builtin can call. The
callback function will provide a single value for each call,
transferred by setting the value of a nameref variable.
EOF
run_test