1 # This program is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 # simple expansion -- no problem, it's quote_string_for_globbing that was flawed
20 # first, match some regular expressions containing ^A, ^G, ^?
21 [[ $'\001' =~ $'\001' ]] ; echo $?
22 [[ $'\001' =~ $'\\\001' ]] ; echo $?
23 [[ $'\001' =~ $'\\[\001]' ]] ; echo $?
25 [[ $'\a' =~ $'\a' ]] ; echo $?
26 [[ $'\a' =~ $'\\\a' ]] ; echo $?
27 [[ $'\a' =~ $'\\[\a]' ]] ; echo $?
29 [[ $'\177' =~ $'\177' ]] ; echo $?
30 [[ $'\177' =~ $'\\\177' ]] ; echo $?
31 [[ $'\177' =~ $'\\[\177]' ]] ; echo $?
33 # Now let's try it with variables expanding to those values
34 for c in $'\001' $'\a' $'\177' ; do
35 for r in "$c" "\\$c" "\\[$c]"; do
37 printf '[[ %q =~ %q ]] -> %d\n' "$c" "$r" "$?";
42 # try again with literals
44 [[ '
\x01' =~ $'
\x01' ]] ; echo $?
45 [[ '
\x01' =~ '\
\x01' ]] ; echo $?
46 [[ '
\x01' =~ '\[
\x01]' ]] ; echo $?
48 [[ '
\a' =~ '
\a' ]] ; echo $?
49 [[ '
\a' =~ '\
\a' ]] ; echo $?
50 [[ '
\a' =~ '\[
\a]' ]] ; echo $?
52 [[ '
\x7f' =~ $'
\x7f' ]] ; echo $?
53 [[ '
\x7f' =~ '\
\x7f' ]] ; echo $?
54 [[ '
\x7f' =~ '\[
\x7f]' ]] ; echo $?
56 # more expansions, but with literal non-special characters
57 [[ x =~ \x ]] ; echo $?
58 [[ x =~ \\x ]] ; echo $?
61 [[ x =~ ${bs}x ]] ; echo $?
63 [[ x =~ $'\\'x ]] ; echo $?
64 [[ x =~ '\'x ]] ; echo $?
67 [[ a-b =~ ${v} ]] ; echo $?
68 [[ a-b =~ a\-b ]]; echo $?
69 [[ a-b =~ a${bs}-b ]]; echo $?
70 [[ a-b =~ a\\-b ]] ; echo $?
71 [[ a-b =~ "a\-b" ]] ; echo $?
77 [[ $c == $c ]] && echo ok 1
78 [[ $c =~ $c ]] && echo ok 2
79 [[ $c =~ \\$c ]] || echo ok 3
80 [[ $c =~ \\"$c" ]] || echo ok 4
82 [[ $c =~ "\\"$c ]] || echo ok 5
83 [[ $c =~ '\'$c ]] || echo ok 6
85 [[ $c =~ "\\""$c" ]] || echo ok 7
86 [[ $c =~ '\'"$c" ]] || echo ok 8