3 # these should output error messages -- the format is required
7 # these should output nothing
11 # this should expand escape sequences in the format string, nothing else
14 # this should not cut off output after the \c
17 # and unrecognized backslash escapes should have the backslash preserverd
20 printf "no newline " ; printf "now newline\n"
25 # simple character output
28 # test simple string output
29 printf "%s\n" unquoted
31 # test quoted string output
32 printf "%s %q\n" unquoted quoted
33 printf "%s%10q\n" unquoted quoted
35 printf "%q\n" 'this&that'
37 # make sure the format string is reused to use up arguments
38 printf "%d " 1 2 3 4 5; printf "\n"
40 # make sure that extra format characters get null arguments
41 printf "%s %d %d %d\n" onestring
43 printf "%s %d %u %4.2f\n" onestring
45 printf -- "--%s %s--\n" 4.2 ''
46 printf -- "--%s %s--\n" 4.2
50 # 8 is a non-octal digit, so the `81' should be output
51 printf -- "--%b--\n" '\n\081'
53 printf -- "--%b--\n" '\t\0101'
54 printf -- "--%b--\n" '\t\101'
56 # these should all display `A7'
60 printf "%b\n" '\01017'
62 printf "%b\n" '\x0417'
64 printf -- "--%b--\n" '\"abcd\"'
65 printf -- "--%b--\n" "\'abcd\'"
67 printf -- "--%b--\n" 'a\\x'
69 printf -- "--%b--\n" '\x'
71 Z1=$(printf -- "%b\n" '\a\b\e\f\r\v')
74 if [ "$Z1" != "$Z2" ]; then
75 echo "whoops: printf %b and $'' differ" >&2
79 printf -- "--%b--\n" ''
82 # the stuff following the \c should be ignored, as well as the rest
83 # of the format string
84 printf -- "--%b--\n" '4.2\c5.4\n'; printf "\n"
86 # make sure extra arguments are ignored if the format string doesn't
89 printf " " 4.4 BSD ; printf "\n"
91 # make sure that a fieldwidth and precision of `*' are handled right
92 printf "%10.8s\n" 4.4BSD
93 printf "%*.*s\n" 10 8 4.4BSD
95 printf "%10.8q\n" 4.4BSD
96 printf "%*.*q\n" 10 8 4.4BSD
99 printf "%*b\n" 6 4.4BSD
101 # we handle this crap with homemade code in printf.def
102 printf "%10b\n" 4.4BSD
103 printf -- "--%-10b--\n" 4.4BSD
104 printf "%4.2b\n" 4.4BSD
105 printf "%.3b\n" 4.4BSD
106 printf -- "--%-8b--\n" 4.4BSD
108 # test numeric conversions -- these four lines should echo identically
109 printf "%d %u %i 0%o 0x%x 0x%X\n" 255 255 255 255 255 255
110 printf "%d %u %i %#o %#x %#X\n" 255 255 255 255 255 255
112 printf "%ld %lu %li 0%o 0x%x 0x%X\n" 255 255 255 255 255 255
113 printf "%ld %lu %li %#o %#x %#X\n" 255 255 255 255 255 255
119 printf "%*d\n" 10 -42
121 # test some simple floating point formats
123 printf "%#4.2f\n" 4.2
124 printf "%#4.1f\n" 4.2
126 printf "%*.*f\n" 4 2 4.2
127 printf "%#*.*f\n" 4 2 4.2
128 printf "%#*.*f\n" 4 1 4.2
140 # test some of the more esoteric features of POSIX.1 printf
141 printf "%d\n" "'string'"
142 printf "%d\n" '"string"'
144 printf "%#o\n" "'string'"
145 printf "%#o\n" '"string"'
147 printf "%#x\n" "'string'"
148 printf "%#X\n" '"string"'
150 printf "%6.2f\n" "'string'"
151 printf "%6.2f\n" '"string"'
153 # output from these two lines had better be the same
154 printf -- "--%6.4s--\n" abcdefghijklmnopqrstuvwxyz
155 printf -- "--%6.4b--\n" abcdefghijklmnopqrstuvwxyz
158 printf -- "--%12.10s--\n" abcdefghijklmnopqrstuvwxyz
159 printf -- "--%12.10b--\n" abcdefghijklmnopqrstuvwxyz
163 # this should be an overflow, but error messages vary between systems
164 # printf "%lu\n" 4294967296
166 # ...but we cannot use this because some systems (SunOS4, for example),
167 # happily ignore overflow conditions in strtol(3)
168 #printf "%ld\n" 4294967296
170 # in the future this may mean to put the output into VAR, but for
172 printf -v var "%10d" $RANDOM
177 # this caused an infinite loop in older versions of printf