Root/b2/test/subesc

1#!/bin/bash
2. ./Common
3
4#
5# Note that we have to escape things for the shell as well. In general,
6# for any character C, \C becomes C. However, in the case of <<EOF ... EOF,
7# \ is left as is if it doesn't precede a special character.
8#
9
10###############################################################################
11
12tst "substitutions: escape x in regexp" -R '*\\x' <<EOF
13EOF
14
15expect <<EOF
16^.*\\x\$
17EOF
18
19#------------------------------------------------------------------------------
20tst "substitutions: escape * in regexp" -R '*\\*' <<EOF
21EOF
22
23expect <<EOF
24^.*\*\$
25EOF
26
27#------------------------------------------------------------------------------
28
29tst "substitutions: escape . in regexp (implicit)" -R 'x.y' <<EOF
30EOF
31
32expect <<EOF
33^x\.y\$
34EOF
35
36#------------------------------------------------------------------------------
37
38tst "substitutions: escape | in regexp" -R 'a\\\|b' <<EOF
39EOF
40
41expect <<EOF
42^a\\|b\$
43EOF
44
45#------------------------------------------------------------------------------
46
47tst "substitutions: escape \\ in regexp" -R 'x\\\\y' <<EOF
48EOF
49
50expect <<EOF
51^x\\\\y\$
52EOF
53
54#------------------------------------------------------------------------------
55
56tst_fail "substitutions: try to escape EOL in regexp" -R 'x\\' <<EOF
57EOF
58
59expect <<EOF
60dummy:2: regexp ends with backslash
61EOF
62
63#------------------------------------------------------------------------------
64
65tst "substitutions: escape space in regexp (match)" -q '"x=a c"' <<EOF
66!-s
67y=a
68x=a\ c { y=b }
69EOF
70
71expect <<EOF
72y=b
73EOF
74
75#------------------------------------------------------------------------------
76
77tst "substitutions: escape space in regexp (no match)" -q '"x=a b"' <<EOF
78!-s
79y=a
80x=a\ c { y=b }
81EOF
82
83expect <<EOF
84y=a
85EOF
86
87#------------------------------------------------------------------------------
88
89tst "substitutions: escape \$ in value" -q <<EOF
90!-s
91x=y\\$
92EOF
93
94expect <<EOF
95x=y\$
96EOF
97
98#------------------------------------------------------------------------------
99
100tst "substitutions: escape x in value" -q <<EOF
101!-s
102x=y\x
103EOF
104
105expect <<EOF
106x=yx
107EOF
108
109#------------------------------------------------------------------------------
110
111tst "substitutions: escape space in value" -q <<EOF
112!-s
113x=x\ y
114EOF
115
116expect <<EOF
117x=x y
118EOF
119
120#------------------------------------------------------------------------------
121
122tst "substitutions: escape \\ in value" -q <<EOF
123!-s
124x=a\\\\b
125EOF
126
127expect <<EOF
128x=a\\b
129EOF
130
131#------------------------------------------------------------------------------
132
133tst_fail "substitutions: try to escape EOL in value" -q <<EOF
134!-s
135x=y\\
136EOF
137
138expect <<EOF
139s:1: syntax error
140EOF
141
142###############################################################################
143

Archive Download this file

Branches:
master



interactive