Added gitignore entries needed to ignore derived objects generated from full build...
[bash.git] / tests / printf1.sub
blob52612d5ce9e9f8a32c869c169c681be77d9ce72b
1 LC_ALL=C
2 LC_NUMERIC=C
4 unset vv
6 # this should expand escape sequences in the format string, nothing else
7 printf -v vv "\tone\n"
8 printf "%s"  "$vv"
10 # this should not cut off output after the \c
11 printf -v vv "one\ctwo\n"
12 printf "%s"  "$vv"
14 # and unrecognized backslash escapes should have the backslash preserverd
15 printf -v vv "4\.2\n"
16 printf "%s"  "$vv"
18 printf -v vv "no newline " ; printf "%s" "$vv" ; printf -v vv "now newline\n"
19 printf "%s"  "$vv"
21 # %% -> %
22 printf -v vv "%%\n"
23 printf "%s"  "$vv"
25 # this was a bug caused by pre-processing the string for backslash escapes
26 # before doing the `%' format processing -- all versions before bash-2.04
27 printf -v vv "\045"
28 printf "%s"  "$vv"
29 echo
30 printf -v vv "\045d\n"
31 printf "%s"  "$vv"
33 # simple character output
34 printf -v vv "%c\n" ABCD
35 printf "%s"  "$vv"
37 # test simple string output
38 printf -v vv "%s\n" unquoted
39 printf "%s"  "$vv"
41 # test quoted string output
42 printf -v vv "%s %q\n" unquoted quoted
43 printf "%s"  "$vv"
44 printf -v vv "%s%10q\n" unquoted quoted
45 printf "%s"  "$vv"
47 printf -v vv "%q\n" 'this&that'
48 printf "%s"  "$vv"
50 # make sure the format string is reused to use up arguments
51 printf -v vv "%d " 1 2 3 4 5
52 printf "%s"  "$vv"
53 echo
55 # make sure that extra format characters get null arguments
56 printf -v vv "%s %d %d %d\n" onestring
57 printf "%s"  "$vv"
59 printf -v vv "%s %d %u %4.2f\n" onestring
60 printf "%s"  "$vv"
62 printf -v vv -- "--%s %s--\n" 4.2 ''
63 printf "%s"  "$vv"
64 printf -v vv -- "--%s %s--\n" 4.2
65 printf "%s"  "$vv"
67 # test %b escapes
69 # 8 is a non-octal digit, so the `81' should be output
70 #printf -v vv -- "--%b--\n" '\n\081'
71 #printf "%s"  "$vv"
73 printf -v vv -- "--%b--\n" '\t\0101'
74 printf "%s"  "$vv"
75 printf -v vv -- "--%b--\n" '\t\101'
76 printf "%s"  "$vv"
78 # these should all display `A7'
79 printf -v vv "%b\n" '\01017'
80 printf "%s"  "$vv"
81 printf -v vv "%b\n" '\1017'
82 printf "%s"  "$vv"
83 printf -v vv "%b\n" '\x417'
84 printf "%s"  "$vv"
86 printf -v vv -- "--%b--\n" '\"abcd\"'
87 printf "%s"  "$vv"
88 printf -v vv -- "--%b--\n" "\'abcd\'"
89 printf "%s"  "$vv"
91 printf -v vv -- "--%b--\n" 'a\\x'
92 printf "%s"  "$vv"
94 printf -v vv -- "--%b--\n" '\x'
95 printf "%s"  "$vv"
97 Z1=$(printf -- "%b\n" '\a\b\e\f\r\v')
98 Z2=$'\a\b\e\f\r\v'
100 if [ "$Z1" != "$Z2" ]; then
101         printf "%s"  "whoops: printf -v vv %b and $'' differ" >&2
103 unset Z1 Z2
105 printf -v vv -- "--%b--\n" ''
106 printf "%s"  "$vv"
107 printf -v vv -- "--%b--\n"
108 printf "%s"  "$vv"
110 # the stuff following the \c should be ignored, as well as the rest
111 # of the format string
112 printf -v vv -- "--%b--\n" '4.2\c5.4\n'
113 printf "%s"  "$vv"
114 echo
116 # unrecognized escape sequences should by displayed unchanged
117 printf -v vv -- "--%b--\n" '4\.2'
118 printf "%s"  "$vv"
120 # a bare \ should not be processed as an escape sequence
121 printf -v vv -- "--%b--\n" '\'
122 printf "%s"  "$vv"
124 # make sure extra arguments are ignored if the format string doesn't
125 # actually use them
126 printf -v vv "\n" 4.4 BSD
127 printf "%s"  "$vv"
128 printf -v vv " " 4.4 BSD
129 printf "%s"  "$vv"
130 echo
132 # make sure that a fieldwidth and precision of `*' are handled right
133 printf -v vv "%10.8s\n" 4.4BSD
134 printf "%s"  "$vv"
135 printf -v vv "%*.*s\n" 10 8 4.4BSD
136 printf "%s"  "$vv"
138 printf -v vv "%10.8q\n" 4.4BSD
139 printf "%s"  "$vv"
140 printf -v vv "%*.*q\n" 10 8 4.4BSD
141 printf "%s"  "$vv"
143 printf -v vv "%6b\n" 4.4BSD
144 printf "%s"  "$vv"
145 printf -v vv "%*b\n" 6 4.4BSD
146 printf "%s"  "$vv"
148 # we handle this crap with homemade code in printf -v vv.def
149 printf -v vv "%10b\n" 4.4BSD
150 printf "%s"  "$vv"
151 printf -v vv -- "--%-10b--\n" 4.4BSD
152 printf "%s"  "$vv"
153 printf -v vv "%4.2b\n" 4.4BSD
154 printf "%s"  "$vv"
155 printf -v vv "%.3b\n" 4.4BSD
156 printf "%s"  "$vv"
157 printf -v vv -- "--%-8b--\n" 4.4BSD
158 printf "%s"  "$vv"
160 # test numeric conversions -- these four lines should printf "%s"  identically
161 printf -v vv "%d %u %i 0%o 0x%x 0x%X\n" 255 255 255 255 255 255
162 printf "%s"  "$vv"
163 printf -v vv "%d %u %i %#o %#x %#X\n" 255 255 255 255 255 255
164 printf "%s"  "$vv"
166 printf -v vv "%ld %lu %li 0%o 0x%x 0x%X\n" 255 255 255 255 255 255
167 printf "%s"  "$vv"
168 printf -v vv "%ld %lu %li %#o %#x %#X\n" 255 255 255 255 255 255
169 printf "%s"  "$vv"
171 printf -v vv "%10d\n" 42
172 printf "%s"  "$vv"
173 printf -v vv "%10d\n" -42
174 printf "%s"  "$vv"
176 printf -v vv "%*d\n" 10 42
177 printf "%s"  "$vv"
178 printf -v vv "%*d\n" 10 -42
179 printf "%s"  "$vv"
181 # test some simple floating point formats
182 printf -v vv "%4.2f\n" 4.2
183 printf "%s"  "$vv"
184 printf -v vv "%#4.2f\n" 4.2
185 printf "%s"  "$vv"
186 printf -v vv "%#4.1f\n" 4.2
187 printf "%s"  "$vv"
189 printf -v vv "%*.*f\n" 4 2 4.2
190 printf "%s"  "$vv"
191 printf -v vv "%#*.*f\n" 4 2 4.2
192 printf "%s"  "$vv"
193 printf -v vv "%#*.*f\n" 4 1 4.2
194 printf "%s"  "$vv"
196 printf -v vv "%E\n" 4.2
197 printf "%s"  "$vv"
198 printf -v vv "%e\n" 4.2
199 printf "%s"  "$vv"
200 printf -v vv "%6.1E\n" 4.2
201 printf "%s"  "$vv"
202 printf -v vv "%6.1e\n" 4.2
203 printf "%s"  "$vv"
205 printf -v vv "%G\n" 4.2
206 printf "%s"  "$vv"
207 printf -v vv "%g\n" 4.2
208 printf "%s"  "$vv"
209 printf -v vv "%6.2G\n" 4.2
210 printf "%s"  "$vv"
211 printf -v vv "%6.2g\n" 4.2
212 printf "%s"  "$vv"
214 # test some of the more esoteric features of POSIX.1 printf -v vv
215 printf -v vv "%d\n" "'string'"
216 printf "%s"  "$vv"
217 printf -v vv "%d\n" '"string"'
218 printf "%s"  "$vv"
220 printf -v vv "%#o\n" "'string'"
221 printf "%s"  "$vv"
222 printf -v vv "%#o\n" '"string"'
223 printf "%s"  "$vv"
225 printf -v vv "%#x\n" "'string'"
226 printf "%s"  "$vv"
227 printf -v vv "%#X\n" '"string"'
228 printf "%s"  "$vv"
230 printf -v vv "%6.2f\n" "'string'"
231 printf "%s"  "$vv"
232 printf -v vv "%6.2f\n" '"string"'
233 printf "%s"  "$vv"
235 # output from these two lines had better be the same
236 printf -v vv -- "--%6.4s--\n" abcdefghijklmnopqrstuvwxyz
237 printf "%s"  "$vv"
238 printf -v vv -- "--%6.4b--\n" abcdefghijklmnopqrstuvwxyz
239 printf "%s"  "$vv"
241 # and these two also
242 printf -v vv -- "--%12.10s--\n" abcdefghijklmnopqrstuvwxyz
243 printf "%s"  "$vv"
244 printf -v vv -- "--%12.10b--\n" abcdefghijklmnopqrstuvwxyz
245 printf "%s"  "$vv"
247 # tests for translating \' to ' and \\ to \
248 # printf -v vv translates \' to ' in the format string...
249 printf -v vv "\'abcd\'\n"
250 printf "%s"  "$vv"
252 # but not when the %b format specification is used
253 printf -v vv "%b\n" \\\'abcd\\\'
254 printf "%s"  "$vv"
256 # but both translate \\ to \
257 printf -v vv '\\abcd\\\n'
258 printf "%s"  "$vv"
259 printf -v vv "%b\n" '\\abcd\\'
260 printf "%s"  "$vv"
262 # this was reported as a bug in bash-2.03
263 # these three lines should all printf "%s"  `26'
264 printf -v vv "%d\n" 0x1a
265 printf "%s"  "$vv"
266 printf -v vv "%d\n" 032
267 printf "%s"  "$vv"
268 printf -v vv "%d\n" 26
269 printf "%s"  "$vv"
271 # error messages
273 # this should be an overflow, but error messages vary between systems
274 # printf -v vv "%lu\n" 4294967296
276 # ...but we cannot use this because some systems (SunOS4, for example),
277 # happily ignore overflow conditions in strtol(3)
278 #printf -v vv "%ld\n" 4294967296
280 printf -v vv "%10"
281 printf -v vv "ab%Mcd\n"
283 # this caused an infinite loop in older versions of printf -v vv
284 printf -v vv "%y" 0
286 # these should print a warning and `0', according to POSIX.2
287 printf -v vv "%d\n" GNU
288 printf "%s"  "$vv"
289 printf -v vv "%o\n" GNU
290 printf "%s"  "$vv"
292 # failures in all bash versions through bash-2.05
293 printf -v vv "%.0s" foo
294 printf "%s"  "$vv"
295 printf -v vv "%.*s" 0 foo
296 printf "%s"  "$vv"
298 printf -v vv '%.0b-%.0s\n' foo bar
299 printf "%s"  "$vv"
300 printf -v vv '(%*b)(%*s)\n' -4 foo -4 bar
301 printf "%s"  "$vv"
303 format='%'`printf '%0100384d' 0`'d\n' 
304 printf -v vv $format 0
305 printf "%s"  "$vv"
307 # failures in all bash versions through bash-3.0 - undercounted characters
308 unset vv
309 printf -v vv "  %s %s %s  \n%n" ab cd ef vvv
310 printf "%s" "$vv"
311 echo $vvv
313 # this doesn't work with printf -v vv(3) on all systems
314 #printf -v vv "%'s\n" foo
316 # test cases from an austin-group list discussion
317 # prints ^G as an extension
318 printf -v vv '%b\n' '\7'
319 printf "%s"  "$vv"
321 # prints ^G
322 printf -v vv '%b\n' '\0007'
323 printf "%s"  "$vv"
325 # prints NUL then 7
326 #printf -v vv '\0007\n'
327 #printf "%s"  "$vv"
329 # prints no more than two hex digits
330 printf -v vv '\x07e\n'
331 printf "%s"  "$vv"
333 # additional backslash escapes
334 printf -v vv '\"\?\n'
335 printf "%s"  "$vv"