6 # this should expand escape sequences in the format string, nothing else
10 # this should not cut off output after the \c
11 printf -v vv "one\ctwo\n"
14 # and unrecognized backslash escapes should have the backslash preserverd
18 printf -v vv "no newline " ; printf "%s" "$vv" ; printf -v vv "now newline\n"
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
30 printf -v vv "\045d\n"
33 # simple character output
34 printf -v vv "%c\n" ABCD
37 # test simple string output
38 printf -v vv "%s\n" unquoted
41 # test quoted string output
42 printf -v vv "%s %q\n" unquoted quoted
44 printf -v vv "%s%10q\n" unquoted quoted
47 printf -v vv "%q\n" 'this&that'
50 # make sure the format string is reused to use up arguments
51 printf -v vv "%d " 1 2 3 4 5
55 # make sure that extra format characters get null arguments
56 printf -v vv "%s %d %d %d\n" onestring
59 printf -v vv "%s %d %u %4.2f\n" onestring
62 printf -v vv -- "--%s %s--\n" 4.2 ''
64 printf -v vv -- "--%s %s--\n" 4.2
69 # 8 is a non-octal digit, so the `81' should be output
70 #printf -v vv -- "--%b--\n" '\n\081'
73 printf -v vv -- "--%b--\n" '\t\0101'
75 printf -v vv -- "--%b--\n" '\t\101'
78 # these should all display `A7'
79 printf -v vv "%b\n" '\01017'
81 printf -v vv "%b\n" '\1017'
83 printf -v vv "%b\n" '\x417'
86 printf -v vv -- "--%b--\n" '\"abcd\"'
88 printf -v vv -- "--%b--\n" "\'abcd\'"
91 printf -v vv -- "--%b--\n" 'a\\x'
94 printf -v vv -- "--%b--\n" '\x'
97 Z1=$(printf -- "%b\n" '\a\b\e\f\r\v')
100 if [ "$Z1" != "$Z2" ]; then
101 printf "%s" "whoops: printf -v vv %b and $'' differ" >&2
105 printf -v vv -- "--%b--\n" ''
107 printf -v vv -- "--%b--\n"
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'
116 # unrecognized escape sequences should by displayed unchanged
117 printf -v vv -- "--%b--\n" '4\.2'
120 # a bare \ should not be processed as an escape sequence
121 printf -v vv -- "--%b--\n" '\'
124 # make sure extra arguments are ignored if the format string doesn't
126 printf -v vv "\n" 4.4 BSD
128 printf -v vv " " 4.4 BSD
132 # make sure that a fieldwidth and precision of `*' are handled right
133 printf -v vv "%10.8s\n" 4.4BSD
135 printf -v vv "%*.*s\n" 10 8 4.4BSD
138 printf -v vv "%10.8q\n" 4.4BSD
140 printf -v vv "%*.*q\n" 10 8 4.4BSD
143 printf -v vv "%6b\n" 4.4BSD
145 printf -v vv "%*b\n" 6 4.4BSD
148 # we handle this crap with homemade code in printf -v vv.def
149 printf -v vv "%10b\n" 4.4BSD
151 printf -v vv -- "--%-10b--\n" 4.4BSD
153 printf -v vv "%4.2b\n" 4.4BSD
155 printf -v vv "%.3b\n" 4.4BSD
157 printf -v vv -- "--%-8b--\n" 4.4BSD
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
163 printf -v vv "%d %u %i %#o %#x %#X\n" 255 255 255 255 255 255
166 printf -v vv "%ld %lu %li 0%o 0x%x 0x%X\n" 255 255 255 255 255 255
168 printf -v vv "%ld %lu %li %#o %#x %#X\n" 255 255 255 255 255 255
171 printf -v vv "%10d\n" 42
173 printf -v vv "%10d\n" -42
176 printf -v vv "%*d\n" 10 42
178 printf -v vv "%*d\n" 10 -42
181 # test some simple floating point formats
182 printf -v vv "%4.2f\n" 4.2
184 printf -v vv "%#4.2f\n" 4.2
186 printf -v vv "%#4.1f\n" 4.2
189 printf -v vv "%*.*f\n" 4 2 4.2
191 printf -v vv "%#*.*f\n" 4 2 4.2
193 printf -v vv "%#*.*f\n" 4 1 4.2
196 printf -v vv "%E\n" 4.2
198 printf -v vv "%e\n" 4.2
200 printf -v vv "%6.1E\n" 4.2
202 printf -v vv "%6.1e\n" 4.2
205 printf -v vv "%G\n" 4.2
207 printf -v vv "%g\n" 4.2
209 printf -v vv "%6.2G\n" 4.2
211 printf -v vv "%6.2g\n" 4.2
214 # test some of the more esoteric features of POSIX.1 printf -v vv
215 printf -v vv "%d\n" "'string'"
217 printf -v vv "%d\n" '"string"'
220 printf -v vv "%#o\n" "'string'"
222 printf -v vv "%#o\n" '"string"'
225 printf -v vv "%#x\n" "'string'"
227 printf -v vv "%#X\n" '"string"'
230 printf -v vv "%6.2f\n" "'string'"
232 printf -v vv "%6.2f\n" '"string"'
235 # output from these two lines had better be the same
236 printf -v vv -- "--%6.4s--\n" abcdefghijklmnopqrstuvwxyz
238 printf -v vv -- "--%6.4b--\n" abcdefghijklmnopqrstuvwxyz
242 printf -v vv -- "--%12.10s--\n" abcdefghijklmnopqrstuvwxyz
244 printf -v vv -- "--%12.10b--\n" abcdefghijklmnopqrstuvwxyz
247 # tests for translating \' to ' and \\ to \
248 # printf -v vv translates \' to ' in the format string...
249 printf -v vv "\'abcd\'\n"
252 # but not when the %b format specification is used
253 printf -v vv "%b\n" \\\'abcd\\\'
256 # but both translate \\ to \
257 printf -v vv '\\abcd\\\n'
259 printf -v vv "%b\n" '\\abcd\\'
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
266 printf -v vv "%d\n" 032
268 printf -v vv "%d\n" 26
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
281 printf -v vv "ab%Mcd\n"
283 # this caused an infinite loop in older versions of printf -v vv
286 # these should print a warning and `0', according to POSIX.2
287 printf -v vv "%d\n" GNU
289 printf -v vv "%o\n" GNU
292 # failures in all bash versions through bash-2.05
293 printf -v vv "%.0s" foo
295 printf -v vv "%.*s" 0 foo
298 printf -v vv '%.0b-%.0s\n' foo bar
300 printf -v vv '(%*b)(%*s)\n' -4 foo -4 bar
303 format='%'`printf '%0100384d' 0`'d\n'
304 printf -v vv $format 0
307 # failures in all bash versions through bash-3.0 - undercounted characters
309 printf -v vv " %s %s %s \n%n" ab cd ef 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'
322 printf -v vv '%b\n' '\0007'
326 #printf -v vv '\0007\n'
329 # prints no more than two hex digits
330 printf -v vv '\x07e\n'
333 # additional backslash escapes
334 printf -v vv '\"\?\n'