-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_read_array
executable file
·69 lines (59 loc) · 1.79 KB
/
test_read_array
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
#!/usr/bin/env bash
source mod_common
bi_enable
cat <<EOF
${B}
Demonstrate builtin function 'read_array'
=========================================
${X}
Array variables are a very useful Bash feature that I want to
be able to access from the builtin C code. This function is
an experiment for access to script-declared arrays.
This experiment declares and initializes an array variable,
then passes the name of the variable to a builtin function
named ${B}read_array${X}.
EOF
run_test()
{
local -a myarray
myarray=( One Two Three Four Five )
myarray+=( Six )
local -a rearr=(
^
\( # group 1
[^@]+ # recipient
\)
@ # match but don't capture
\( # group 2
.\* # sub-domain. Prevent OS substitution with
# single-escaped asterisk
\)
\( # group 3
\\. # match but don't capture. Prevent regex wildcard
# match with double-escaped dot
\( # group 4
[^\\.]+ # match non-dot characters, prevent regex wildcard match
\)
\)
$
)
local OIFS="$IFS"
local IFS=''
local re="${rearr[*]}"
echo "re is $B${re}$X"
IFS="$OIFS"
unset OIFS
local email_addr="[email protected]"
echo "About to part $B${email_addr}$X with the regular expression."
if [[ "$email_addr" =~ $re ]]; then
echo "String matched the regular expression"
else
echo "String failed to match the regular expression"
fi
echo
echo "About to call $Bread_array$X with the two arrays."
echo "Output after this point generated by the builtin."
echo
read_array "myarray" "BASH_REMATCH"
}
run_test