Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/ksh93/tests/quoting2.sh
1810 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1982-2011 AT&T Intellectual Property #
5
# and is licensed under the #
6
# Eclipse Public License, Version 1.0 #
7
# by AT&T Intellectual Property #
8
# #
9
# A copy of the License is available at #
10
# http://www.eclipse.org/org/documents/epl-v10.html #
11
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12
# #
13
# Information and Software Systems Research #
14
# AT&T Research #
15
# Florham Park NJ #
16
# #
17
# David Korn <[email protected]> #
18
# #
19
########################################################################
20
function err_exit
21
{
22
print -u2 -n "\t"
23
print -u2 -r ${Command}[$1]: "${@:2}"
24
let Errors+=1
25
}
26
alias err_exit='err_exit $LINENO'
27
28
Command=${0##*/}
29
integer Errors=0
30
set -o noglob
31
if [[ 'hi there' != "hi there" ]]
32
then err_exit "single quotes not the same as double quotes"
33
fi
34
x='hi there'
35
if [[ $x != 'hi there' ]]
36
then err_exit "$x not the same as 'hi there'"
37
fi
38
if [[ $x != "hi there" ]]
39
then err_exit "$x not the same as \"hi there \""
40
fi
41
if [[ \a\b\c\*\|\"\ \\ != 'abc*|" \' ]]
42
then err_exit " \\ differs from '' "
43
fi
44
if [[ "ab\'\"\$(" != 'ab\'\''"$(' ]]
45
then err_exit " \"\" differs from '' "
46
fi
47
if [[ $(print -r - 'abc*|" \') != 'abc*|" \' ]]
48
then err_exit "\$(print -r - '') differs from ''"
49
fi
50
if [[ $(print -r - "abc*|\" \\") != 'abc*|" \' ]]
51
then err_exit "\$(print -r - '') differs from ''"
52
fi
53
if [[ "$(print -r - 'abc*|" \')" != 'abc*|" \' ]]
54
then err_exit "\"\$(print -r - '')\" differs from ''"
55
fi
56
if [[ "$(print -r - "abc*|\" \\")" != 'abc*|" \' ]]
57
then err_exit "\"\$(print -r - "")\" differs from ''"
58
fi
59
if [[ $(print -r - "$(print -r - 'abc*|" \')") != 'abc*|" \' ]]
60
then err_exit "nested \$(print -r - '') differs from ''"
61
fi
62
if [[ "$(print -r - $(print -r - 'abc*|" \'))" != 'abc*|" \' ]]
63
then err_exit "\"nested \$(print -r - '')\" differs from ''"
64
fi
65
if [[ $(print -r - "$(print -r - 'abc*|" \')") != 'abc*|" \' ]]
66
then err_exit "nested \"\$(print -r - '')\" differs from ''"
67
fi
68
unset x
69
if [[ ${x-$(print -r - "abc*|\" \\")} != 'abc*|" \' ]]
70
then err_exit "\${x-\$(print -r - '')} differs from ''"
71
fi
72
if [[ ${x-$(print -r - "a}c*|\" \\")} != 'a}c*|" \' ]]
73
then err_exit "\${x-\$(print -r - '}')} differs from ''"
74
fi
75
x=$((echo foo)|(cat))
76
if [[ $x != foo ]]
77
then err_exit "((cmd)|(cmd)) failed"
78
fi
79
x=$(print -r -- "\"$HOME\"")
80
if [[ $x != '"'$HOME'"' ]]
81
then err_exit "nested double quotes failed"
82
fi
83
unset z
84
: ${z="a{b}c"}
85
if [[ $z != 'a{b}c' ]]
86
then err_exit '${z="a{b}c"} not correct'
87
fi
88
unset z
89
: "${z="a{b}c"}"
90
if [[ $z != 'a{b}c' ]]
91
then err_exit '"${z="a{b}c"}" not correct'
92
fi
93
if [[ $(print -r -- "a\*b") != 'a\*b' ]]
94
then err_exit '$(print -r -- "a\*b") differs from a\*b'
95
fi
96
unset x
97
if [[ $(print -r -- "a\*b$x") != 'a\*b' ]]
98
then err_exit '$(print -r -- "a\*b$x") differs from a\*b'
99
fi
100
x=hello
101
set -- ${x+foo bar bam}
102
if (( $# !=3 ))
103
then err_exit '${x+foo bar bam} does not yield three arguments'
104
fi
105
set -- ${x+foo "bar bam"}
106
if (( $# !=2 ))
107
then err_exit '${x+foo "bar bam"} does not yield two arguments'
108
fi
109
set -- ${x+foo 'bar bam'}
110
if (( $# !=2 ))
111
then err_exit '${x+foo '\''bar bam'\''} does not yield two arguments'
112
fi
113
set -- ${x+foo $x bam}
114
if (( $# !=3 ))
115
then err_exit '${x+foo $x bam} does not yield three arguments'
116
fi
117
set -- ${x+foo "$x" bam}
118
if (( $# !=3 ))
119
then err_exit '${x+foo "$x" bam} does not yield three arguments'
120
fi
121
set -- ${x+"foo $x bam"}
122
if (( $# !=1 ))
123
then err_exit '${x+"foo $x bam"} does not yield one argument'
124
fi
125
set -- "${x+foo $x bam}"
126
if (( $# !=1 ))
127
then err_exit '"${x+foo $x bam}" does not yield one argument'
128
fi
129
set -- ${x+foo "$x "bam}
130
if (( $# !=2 ))
131
then err_exit '${x+foo "$x "bam} does not yield two arguments'
132
fi
133
x="ab$'cd"
134
if [[ $x != 'ab$'"'cd" ]]
135
then err_exit '$'"' inside double quotes not working"
136
fi
137
x=`print 'ab$'`
138
if [[ $x != 'ab$' ]]
139
then err_exit '$'"' inside `` quotes not working"
140
fi
141
unset a
142
x=$(print -r -- "'\
143
\
144
")
145
if [[ $x != "'" ]]
146
then err_exit 'line continuation in double strings not working'
147
fi
148
x=$(print -r -- "'\
149
$a\
150
")
151
if [[ $x != "'" ]]
152
then err_exit 'line continuation in expanded double strings not working'
153
fi
154
x='\*'
155
if [[ $(print -r -- $x) != '\*' ]]
156
then err_exit 'x="\\*";$x != \*'
157
fi
158
if [[ $(print -r -- "\}" ) != '\}' ]]
159
then err_exit '(print -r -- "\}"' not working
160
fi
161
if [[ $(print -r -- "\{" ) != '\{' ]]
162
then err_exit 'print -r -- "\{"' not working
163
fi
164
# The following caused a syntax error on earlier versions
165
foo=foo x=-
166
if [[ `eval print \\${foo$x}` != foo* ]]
167
then err_exit '`eval print \\${foo$x}`' not working
168
fi
169
if [[ "`eval print \\${foo$x}`" != foo* ]]
170
then err_exit '"`eval print \\${foo$x}`"' not working
171
fi
172
if ( [[ $() != '' ]] )
173
then err_exit '$() not working'
174
fi
175
x=a:b:c
176
set -- $( IFS=:; print $x)
177
if (( $# != 3))
178
then err_exit 'IFS not working correctly with command substitution'
179
fi
180
$SHELL -n 2> /dev/null << \! || err_exit '$(...) bug with ( in comment'
181
y=$(
182
# ( this line is a bug fix
183
print hi
184
)
185
!
186
x=
187
for j in glob noglob
188
do for i in 'a\*b' 'a\ b' 'a\bc' 'a\*b' 'a\"b'
189
do eval [[ '$('print -r -- \'$i\'\$x')' != "'$i'" ]] && err_exit "quoting of $i\$x with $j enabled failed"
190
eval [[ '$('print -r -- \'$i\'\${x%*}')' != "'$i'" ]] && err_exit "quoting of $i\${x%*} with $j enabled failed"
191
if [[ $j == noglob ]]
192
then eval [[ '$('print -r -- \'$i\'\${x:-*}')' != "'$i''*'" ]] && err_exit "quoting of $i\${x:-*} with $j enabled failed"
193
fi
194
done
195
set -f
196
done
197
foo=foo
198
[[ "$" == '$' ]] || err_exit '"$" != $'
199
[[ "${foo}$" == 'foo$' ]] || err_exit 'foo=foo;"${foo}$" != foo$'
200
[[ "${foo}${foo}$" == 'foofoo$' ]] || err_exit 'foo=foo;"${foo}${foo}$" != foofoo$'
201
foo='$ '
202
[[ "$foo" == ~(Elr)(\\\$|#)\ ]] || err_exit $'\'$ \' not matching RE \\\\\\$|#\''
203
[[ "$foo" == ~(Elr)('\$'|#)\ ]] || err_exit $'\'$ \' not matching RE \'\\$\'|#\''
204
foo='# '
205
[[ "$foo" == ~(Elr)(\\\$|#)\ ]] || err_exit $'\'# \' not matching RE \\'\$|#\''
206
[[ "$foo" == ~(Elr)('\$'|#)\ ]] || err_exit $'\'# \' not matching RE \'\\$\'|#\''
207
[[ '\$' == '\$'* ]] || err_exit $'\'\\$\' not matching \'\\$\'*'
208
[[ a+a == ~(E)a\+a ]] || err_exit '~(E)a\+a not matching a+a'
209
[[ a+a =~ a\+a ]] || err_exit 'RE a\+a not matching a+a'
210
211
exp='ac'
212
got=$'a\0b'c
213
[[ $got == "$exp" ]] || err_exit "\$'a\\0b'c expansion failed -- expected '$exp', got '$got'"
214
215
exit $((Errors<125?Errors:125))
216
217