]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/nquote.tests
bash-5.1-alpha release
[thirdparty/bash.git] / tests / nquote.tests
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.
5 #
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.
10 #
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/>.
13 #
14 expect()
15 {
16 echo expect "$@"
17 }
18
19 expect '<^J^J^J>'
20 recho $'\n\n\n'
21
22 expect '<++^J++>'
23 f=$'\n'
24 recho "++$f++"
25 unset f
26
27 z1=$''
28 expect '<>'
29 recho "$z1"
30
31 ZIFS=$'\n'$'\t'$' '
32
33 expect '<^J^I >'
34 recho "$ZIFS"
35
36 expect '<abc>'
37 recho $'abc'
38
39 expect '<^M^[^Gabc>'
40 recho $'\r\e\aabc'
41
42 D=$"hello"," "$"world"
43
44 expect '<hello,> <world>'
45 recho $D
46
47 expect '<hello, world>'
48 recho "$D"
49
50 D=$""
51 expect '<>'
52 recho "$D"
53
54 world=chet
55
56 expect '<$hello, world>'
57 recho \$"hello, world"
58
59 expect '<hello, $world>'
60 recho $"hello, \$world"
61
62 expect '<hello, "world">'
63 recho $"hello, \"world\""
64
65 expect '<hello, $"world">'
66 recho $"hello"', $"world"'
67
68 expect '<hello, $"world">'
69 recho $'hello, $"world"'
70
71 expect '<$hello, chet>'
72 recho \$"hello, $world"
73
74 expect '<hello, chet>'
75 recho $"hello, $world"
76
77 z=$'\v\f\a\b'
78 case "$z" in
79 $'\v\f\a\b') echo ok;;
80 *) echo bad;;
81 esac
82
83 # Dave Korn says this should be allowed and echo 'abcd'
84 echo $'\'abcd\''
85
86 # printf translates \' to ' ...
87 printf "\'abcd\'\n"
88
89 # but echo -e doesn't
90 echo -e "\'abcd\'"
91 echo -e "\\'abcd\\'"
92
93 # and what do we do about unrecognized escape sequences?
94
95 shopt -s xpg_echo
96
97 recho $'A\CB'
98
99 recho "A\CB"
100
101 cde=c
102 recho $'ab$cde'
103
104 printf "%b\n" 'A\CB'
105 printf 'A\CB\n'
106
107 echo 'A\CB'
108
109 world=chet
110
111 recho $'hello, $"world"'
112 recho $'hello, \$"world"'
113 recho $'hello, $\"world"'
114
115 recho "hello, $"world""
116
117 # ansi quoting inside double-quoted command subst - bash-3.1 bug
118 echo $(set -- $'a b'; echo $#)
119 echo "$(set -- $'a b'; echo $#)"
120
121 echo "$(echo $';foo')"
122
123 args ()
124 {
125 for a in "$@";do echo "'$a'";done
126 }
127 unset mytab
128 recho "${mytab:-$'\t'}"
129 recho "$( args $'A\tB' )"
130
131 ${THIS_SH} ./nquote1.sub
132 ${THIS_SH} ./nquote2.sub
133 ${THIS_SH} ./nquote3.sub