]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/cond-regexp3.sub
Bash-4.3 patch 7
[thirdparty/bash.git] / tests / cond-regexp3.sub
CommitLineData
ac50fbac
CR
1# simple expansion -- no problem, it's quote_string_for_globbing that was flawed
2c=$'\177'
3r="\\$c"
4
5recho $r
6
7# first, match some regular expressions containing ^A, ^G, ^?
8[[ $'\001' =~ $'\001' ]] ; echo $?
9[[ $'\001' =~ $'\\\001' ]] ; echo $?
10[[ $'\001' =~ $'\\[\001]' ]] ; echo $?
11
12[[ $'\a' =~ $'\a' ]] ; echo $?
13[[ $'\a' =~ $'\\\a' ]] ; echo $?
14[[ $'\a' =~ $'\\[\a]' ]] ; echo $?
15
16[[ $'\177' =~ $'\177' ]] ; echo $?
17[[ $'\177' =~ $'\\\177' ]] ; echo $?
18[[ $'\177' =~ $'\\[\177]' ]] ; echo $?
19
20# Now let's try it with variables expanding to those values
21for c in $'\001' $'\a' $'\177' ; do
22 for r in "$c" "\\$c" "\\[$c]"; do
23 [[ $c =~ $r ]];
24 printf '[[ %q =~ %q ]] -> %d\n' "$c" "$r" "$?";
25 done;
26 printf %s\\n ---
27done
28
29# try again with literals
30
31[[ '\ 1' =~ $'\ 1' ]] ; echo $?
32[[ '\ 1' =~ '\\ 1' ]] ; echo $?
33[[ '\ 1' =~ '\[\ 1]' ]] ; echo $?
34
35[[ '\a' =~ '\a' ]] ; echo $?
36[[ '\a' =~ '\\a' ]] ; echo $?
37[[ '\a' =~ '\[\a]' ]] ; echo $?
38
39[[ '\7f' =~ $'\7f' ]] ; echo $?
40[[ '\7f' =~ '\\7f' ]] ; echo $?
41[[ '\7f' =~ '\[\7f]' ]] ; echo $?
42
43# more expansions, but with literal non-special characters
44[[ x =~ \x ]] ; echo $?
45[[ x =~ \\x ]] ; echo $?
46
47bs='\'
48[[ x =~ ${bs}x ]] ; echo $?
49
50[[ x =~ $'\\'x ]] ; echo $?
51[[ x =~ '\'x ]] ; echo $?
52
53v='a\-b'
54[[ a-b =~ ${v} ]] ; echo $?
55[[ a-b =~ a\-b ]]; echo $?
56[[ a-b =~ a${bs}-b ]]; echo $?
57[[ a-b =~ a\\-b ]] ; echo $?
58[[ a-b =~ "a\-b" ]] ; echo $?
59
60c=$'\001'
61
62recho $c "$c"
63
64[[ $c == $c ]] && echo ok 1
65[[ $c =~ $c ]] && echo ok 2
66[[ $c =~ \\$c ]] || echo ok 3
67[[ $c =~ \\"$c" ]] || echo ok 4
68
69[[ $c =~ "\\"$c ]] || echo ok 5
70[[ $c =~ '\'$c ]] || echo ok 6
71
72[[ $c =~ "\\""$c" ]] || echo ok 7
73[[ $c =~ '\'"$c" ]] || echo ok 8