1 '\" te 2 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved 3 .\" Copyright 1992, X/Open Company Limited All Rights Reserved 4 .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures 5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/. 6 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text 7 .\" are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical 8 .\" and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html. 9 .\" This notice shall appear on any product containing this material. 10 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. 11 .\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with 12 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] 13 .TH PRINTF 1 "Aug 11, 2009" 14 .SH NAME 15 printf \- write formatted output 16 .SH SYNOPSIS 17 .SS "/usr/bin/printf" 18 .LP 19 .nf 20 \fBprintf\fR \fIformat\fR [\fIargument\fR]... 21 .fi 22 23 .SS "ksh93" 24 .LP 25 .nf 26 \fBprintf\fR \fIformat\fR [\fIstring\fR...] 27 .fi 28 29 .SH DESCRIPTION 30 .SS "/usr/bin/printf" 31 .sp 32 .LP 33 The \fBprintf\fR utility writes each string operand to standard output using 34 \fIformat\fR to control the output format. 35 .SH OPERANDS 36 .SS "/usr/bin/printf" 37 .sp 38 .LP 39 The following operands are supported by \fB/usr/bin/printf\fR: 40 .sp 41 .ne 2 42 .na 43 \fB\fIformat\fR\fR 44 .ad 45 .RS 12n 46 A string describing the format to use to write the remaining operands. The 47 \fIformat\fR operand is used as the \fIformat\fR string described on the 48 \fBformats\fR(5) manual page, with the following exceptions: 49 .RS +4 50 .TP 51 .ie t \(bu 52 .el o 53 A \fBSPACE\fR character in the format string, in any context other than a flag 54 of a conversion specification, is treated as an ordinary character that is 55 copied to the output. 56 .RE 57 .RS +4 58 .TP 59 .ie t \(bu 60 .el o 61 A character in the format string is treated as a character, not as a 62 \fBSPACE\fR character. 63 .RE 64 .RS +4 65 .TP 66 .ie t \(bu 67 .el o 68 In addition to the escape sequences described on the \fBformats\fR(5) manual 69 page (\fB\e\e\fR, \fB\ea\fR, \fB\eb\fR, \fB\ef\fR, \fB\en\fR, \fB\er\fR, 70 \fB\et\fR, \fB\ev\fR), \fB\e\fR\fIddd\fR, where \fIddd\fR is a one-, two- or 71 three-digit octal number, is written as a byte with the numeric value specified 72 by the octal number. 73 .RE 74 .RS +4 75 .TP 76 .ie t \(bu 77 .el o 78 The program does not precede or follow output from the \fBd\fR or \fBu\fR 79 conversion specifications with blank characters not specified by the 80 \fIformat\fR operand. 81 .RE 82 .RS +4 83 .TP 84 .ie t \(bu 85 .el o 86 The program does not precede output from the \fBo\fR conversion specification 87 with zeros not specified by the \fIformat\fR operand. 88 .RE 89 .RS +4 90 .TP 91 .ie t \(bu 92 .el o 93 An additional conversion character, \fBb\fR, is supported as follows. The 94 argument is taken to be a string that can contain backslash-escape sequences. 95 The following backslash-escape sequences are supported: 96 .RS +4 97 .TP 98 .ie t \(bu 99 .el o 100 the escape sequences listed on the \fBformats\fR(5) manual page (\fB\e\e\fR, 101 \fB\ea\fR, \fB\eb\fR, \fB\ef\fR, \fB\en\fR, \fB\er\fR, \fB\et\fR, \fB\ev\fR), 102 which are converted to the characters they represent 103 .RE 104 .RS +4 105 .TP 106 .ie t \(bu 107 .el o 108 \fB\e0\fR\fIddd\fR, where \fIddd\fR is a zero-, one-, two- or three-digit octal 109 number that is converted to a byte with the numeric value specified by the 110 octal number 111 .RE 112 .RS +4 113 .TP 114 .ie t \(bu 115 .el o 116 \fB\ec\fR, which is written and causes \fBprintf\fR to ignore any remaining 117 characters in the string operand containing it, any remaining string operands 118 and any additional characters in the \fIformat\fR operand. 119 .RE 120 .RE 121 The interpretation of a backslash followed by any other sequence of characters 122 is unspecified. 123 .sp 124 Bytes from the converted string are written until the end of the string or the 125 number of bytes indicated by the precision specification is reached. If the 126 precision is omitted, it is taken to be infinite, so all bytes up to the end of 127 the converted string are written. For each specification that consumes an 128 argument, the next argument operand is evaluated and converted to the 129 appropriate type for the conversion as specified below. The \fIformat\fR 130 operand is reused as often as necessary to satisfy the argument operands. Any 131 extra \fBc\fR or \fBs\fR conversion specifications are evaluated as if a null 132 string argument were supplied; other extra conversion specifications are 133 evaluated as if a zero argument were supplied. If the \fIformat\fR operand 134 contains no conversion specifications and \fIargument\fR operands are present, 135 the results are unspecified. If a character sequence in the \fIformat\fR 136 operand begins with a \fB%\fR character, but does not form a valid conversion 137 specification, the behavior is unspecified. 138 .RE 139 140 .sp 141 .ne 2 142 .na 143 \fB\fIargument\fR\fR 144 .ad 145 .RS 12n 146 The strings to be written to standard output, under the control of 147 \fBformat\fR. The \fIargument\fR operands are treated as strings if the 148 corresponding conversion character is \fBb\fR, \fBc\fR or \fBs\fR. Otherwise, 149 it is evaluated as a C constant, as described by the ISO C standard, with the 150 following extensions: 151 .RS +4 152 .TP 153 .ie t \(bu 154 .el o 155 A leading plus or minus sign is allowed. 156 .RE 157 .RS +4 158 .TP 159 .ie t \(bu 160 .el o 161 If the leading character is a single- or double-quote, the value is the numeric 162 value in the underlying codeset of the character following the single- or 163 double-quote. 164 .RE 165 If an argument operand cannot be completely converted into an internal value 166 appropriate to the corresponding conversion specification, a diagnostic message 167 is written to standard error and the utility does not exit with a zero exit 168 status, but continues processing any remaining operands and writes the value 169 accumulated at the time the error was detected to standard output. 170 .RE 171 172 .SS "ksh93" 173 .sp 174 .LP 175 The \fIformat\fR operands support the full range of ANSI C/C99/XPG6 formatting 176 specifiers as well as additional specifiers: 177 .sp 178 .ne 2 179 .na 180 \fB\fB%b\fR\fR 181 .ad 182 .RS 6n 183 Each character in the string operand is processed specially, as follows: 184 .sp 185 .ne 2 186 .na 187 \fB\fB\ea\fR\fR 188 .ad 189 .RS 8n 190 Alert character. 191 .RE 192 193 .sp 194 .ne 2 195 .na 196 \fB\fB\eb\fR\fR 197 .ad 198 .RS 8n 199 Backspace character. 200 .RE 201 202 .sp 203 .ne 2 204 .na 205 \fB\fB\ec\fR\fR 206 .ad 207 .RS 8n 208 Terminate output without appending NEWLINE. The remaining string operands are 209 ignored. 210 .RE 211 212 .sp 213 .ne 2 214 .na 215 \fB\fB\eE\fR\fR 216 .ad 217 .RS 8n 218 Escape character (\fBASCII\fR octal \fB033\fR). 219 .RE 220 221 .sp 222 .ne 2 223 .na 224 \fB\fB\ef\fR\fR 225 .ad 226 .RS 8n 227 FORM FEED character. 228 .RE 229 230 .sp 231 .ne 2 232 .na 233 \fB\fB\en\fR\fR 234 .ad 235 .RS 8n 236 NEWLINE character. 237 .RE 238 239 .sp 240 .ne 2 241 .na 242 \fB\fB\et\fR\fR 243 .ad 244 .RS 8n 245 TAB character. 246 .RE 247 248 .sp 249 .ne 2 250 .na 251 \fB\fB\ev\fR\fR 252 .ad 253 .RS 8n 254 Vertical tab character. 255 .RE 256 257 .sp 258 .ne 2 259 .na 260 \fB\fB\e\e\fR\fR 261 .ad 262 .RS 8n 263 Backslash character. 264 .RE 265 266 .sp 267 .ne 2 268 .na 269 \fB\fB\e0\fR\fIx\fR\fR 270 .ad 271 .RS 8n 272 The 8-bit character whose \fBASCII\fR code is the \fB1\fR-, \fB2\fR-, or 273 \fB3\fR-digit octal number \fIx\fR. 274 .RE 275 276 .RE 277 278 .sp 279 .ne 2 280 .na 281 \fB\fB%B\fR\fR 282 .ad 283 .RS 6n 284 Treat the argument as a variable name and output the value without converting 285 it to a string. This is most useful for variables of type \fB-b\fR. 286 .RE 287 288 .sp 289 .ne 2 290 .na 291 \fB\fB%H\fR\fR 292 .ad 293 .RS 6n 294 Output string with characters \fB<\fR, \fB&\fR, \fB>\fR, \fB"\fR, and 295 non-printable characters, properly escaped for use in HTML and XML documents. 296 .RE 297 298 .sp 299 .ne 2 300 .na 301 \fB\fB%P\fR\fR 302 .ad 303 .RS 6n 304 Treat \fIstring\fR as an extended regular expression and convert it to a shell 305 pattern. 306 .RE 307 308 .sp 309 .ne 2 310 .na 311 \fB\fB%q\fR\fR 312 .ad 313 .RS 6n 314 Output \fIstring\fR quoted in a manner that it can be read in by the shell to 315 get back the same string. However, empty strings resulting from missing string 316 operands are not quoted. 317 .RE 318 319 .sp 320 .ne 2 321 .na 322 \fB\fB%R\fR\fR 323 .ad 324 .RS 6n 325 Treat \fIstring\fR as an shell pattern expression and convert it to an extended 326 regular expression. 327 .RE 328 329 .sp 330 .ne 2 331 .na 332 \fB\fB%T\fR\fR 333 .ad 334 .RS 6n 335 Treat \fIstring\fR as a date/time string and format it. The \fBT\fR can be 336 preceded by (\fIdformat\fR), where \fIdformat\fR is a date format as defined by 337 the \fBdate\fR(1) command. 338 .RE 339 340 .sp 341 .ne 2 342 .na 343 \fB\fB%Z\fR\fR 344 .ad 345 .RS 6n 346 Output a byte whose value is \fB0\fR. 347 .RE 348 349 .sp 350 .LP 351 When performing conversions of \fIstring\fR to satisfy a numeric format 352 specifier, if the first character of \fIstring\fR is \fB"or'\fR, the value is 353 the numeric value in the underlying code set of the character following the 354 \fB"or'\fR. Otherwise, \fIstring\fR is treated like a shell arithmetic 355 expression and evaluated. 356 .sp 357 .LP 358 If a \fIstring\fR operand cannot be completely converted into a value 359 appropriate for that format specifier, an error occurs, but remaining 360 \fIstring\fR operands continue to be processed. 361 .sp 362 .LP 363 In addition to the format specifier extensions, the following extensions of 364 ANSI C/C99/XPG6 are permitted in format specifiers: 365 .RS +4 366 .TP 367 .ie t \(bu 368 .el o 369 The escape sequences \fB\eE\fR and \fB\ee\fR expand to the escape character 370 which is octal 033 in ASCII. 371 .RE 372 .RS +4 373 .TP 374 .ie t \(bu 375 .el o 376 The escape sequence \fB\ecx\fR expands to CTRL-x. 377 .RE 378 .RS +4 379 .TP 380 .ie t \(bu 381 .el o 382 The escape sequence \fB\eC[.\fR\fIname\fR\fB\&.]\fR expands to the collating 383 element \fIname\fR. 384 .RE 385 .RS +4 386 .TP 387 .ie t \(bu 388 .el o 389 The escape sequence \fB\ex{hex}\fRexpands to the character corresponding to the 390 hexadecimal value \fBhex\fR. 391 .RE 392 .RS +4 393 .TP 394 .ie t \(bu 395 .el o 396 The format modifier flag = can be used to center a field to a specified width. 397 When the output is a terminal, the character width is used rather than the 398 number of bytes. 399 .RE 400 .RS +4 401 .TP 402 .ie t \(bu 403 .el o 404 Each of the integral format specifiers can have a third modifier after width 405 and precision that specifies the base of the conversion from 2 to 64. In this 406 case, the \fB#\fR modifier causes \fIbase\fR\fB#\fR to be prepended to the 407 value. 408 .RE 409 .RS +4 410 .TP 411 .ie t \(bu 412 .el o 413 The \fB#\fR modifier can be used with the \fBd\fR specifier when no base is 414 specified to cause the output to be written in units of 1000 with a suffix of 415 one of \fBk M G T P E\fR. 416 .RE 417 .RS +4 418 .TP 419 .ie t \(bu 420 .el o 421 The \fB#\fR modifier can be used with the \fBi\fR specifier to cause the output 422 to be written in units of \fB1024\fR with a suffix of one of \fBKi Mi Gi Ti Pi 423 Ei\fR. 424 .RE 425 .sp 426 .LP 427 If there are more \fIstring\fR operands than format specifiers, the format 428 string is reprocessed from the beginning. If there are fewer \fIstring\fR 429 operands than format specifiers, then \fIstring\fR specifiers are treated as if 430 empty strings were supplied, numeric conversions are treated as if \fB0\fR was 431 supplied, and time conversions are treated as if \fBnow\fR was supplied. 432 .sp 433 .LP 434 \fB/usr/bin/printf\fR is equivalent to \fBksh93\fR's \fBprintf\fR built-in and 435 \fBprint -f\fR, which allows additional options to be specified. 436 .SH USAGE 437 .SS "/usr/bin/printf" 438 .sp 439 .LP 440 The \fBprintf\fR utility, like the \fBprintf\fR(3C) function on which it is 441 based, makes no special provision for dealing with multi-byte characters when 442 using the \fB%c\fR conversion specification. Applications should be extremely 443 cautious using either of these features when there are multi-byte characters in 444 the character set. 445 .sp 446 .LP 447 Field widths and precisions cannot be specified as \fB*\fR. 448 .sp 449 .LP 450 The \fB%b\fR conversion specification is not part of the ISO C standard; it has 451 been added here as a portable way to process backslash escapes expanded in 452 string operands as provided by the \fBecho\fR utility. See also the USAGE 453 section of the \fBecho\fR(1) manual page for ways to use \fBprintf\fR as a 454 replacement for all of the traditional versions of the \fBecho\fR utility. 455 .sp 456 .LP 457 If an argument cannot be parsed correctly for the corresponding conversion 458 specification, the \fBprintf\fR utility reports an error. Thus, overflow and 459 extraneous characters at the end of an argument being used for a numeric 460 conversion are to be reported as errors. 461 .sp 462 .LP 463 It is not considered an error if an argument operand is not completely used for 464 a \fBc\fR or \fBs\fR conversion or if a string operand's first or second 465 character is used to get the numeric value of a character. 466 .SH EXAMPLES 467 .SS "/usr/bin/printf" 468 .LP 469 \fBExample 1 \fRPrinting a Series of Prompts 470 .sp 471 .LP 472 The following example alerts the user, then prints and reads a series of 473 prompts: 474 475 .sp 476 .in +2 477 .nf 478 example% \fBprintf "\eaPlease fill in the following: \enName: " 479 read name 480 printf "Phone number: " 481 read phone\fR 482 .fi 483 .in -2 484 .sp 485 486 .LP 487 \fBExample 2 \fRPrinting a Table of Calculations 488 .sp 489 .LP 490 The following example prints a table of calculations. It reads out a list of 491 right and wrong answers from a file, calculates the percentage correctly, and 492 prints them out. The numbers are right-justified and separated by a single tab 493 character. The percentage is written to one decimal place of accuracy: 494 495 .sp 496 .in +2 497 .nf 498 example% \fBwhile read right wrong ; do 499 percent=$(echo "scale=1;($right*100)/($right+$wrong)" | bc) 500 printf "%2d right\et%2d wrong\et(%s%%)\en" \e 501 $right $wrong $percent 502 done < database_file\fR 503 .fi 504 .in -2 505 .sp 506 507 .LP 508 \fBExample 3 \fRPrinting number strings 509 .sp 510 .LP 511 The command: 512 513 .sp 514 .in +2 515 .nf 516 example% \fBprintf "%5d%4d\en" 1 21 321 4321 54321\fR 517 .fi 518 .in -2 519 .sp 520 521 .sp 522 .LP 523 produces: 524 525 .sp 526 .in +2 527 .nf 528 1 21 529 3214321 530 54321 0 531 .fi 532 .in -2 533 .sp 534 535 .sp 536 .LP 537 The \fIformat\fR operand is used three times to print all of the given strings 538 and that a \fB0\fR was supplied by \fBprintf\fR to satisfy the last \fB%4d\fR 539 conversion specification. 540 541 .LP 542 \fBExample 4 \fRTabulating Conversion Errors 543 .sp 544 .LP 545 The following example tabulates conversion errors. 546 547 .sp 548 .LP 549 The \fBprintf\fR utility tells the user when conversion errors are detected 550 while producing numeric output. These results would be expected on an 551 implementation with 32-bit twos-complement integers when \fB%d\fR is specified 552 as the \fIformat\fR operand: 553 554 .sp 555 556 .sp 557 .TS 558 box; 559 c c c 560 l l l . 561 Arguments Standard Diagnostic 562 5a 5 printf: 5a not completely converted 563 9999999999 2147483647 printf: 9999999999: Results too large 564 -9999999999 -2147483648 printf: -9999999999: Results too large 565 ABC 0 printf: ABC expected numeric value 566 .TE 567 568 .sp 569 .LP 570 The value shown on standard output is what would be expected as the return 571 value from the function \fBstrtol\fR(3C). A similar correspondence exists 572 between \fB%u\fR and \fBstrtoul\fR(3C), and \fB%e\fR, \fB%f\fR and \fB%g\fR and 573 \fBstrtod\fR(3C). 574 575 .LP 576 \fBExample 5 \fRPrinting Output for a Specific Locale 577 .sp 578 .LP 579 The following example prints output for a specific locale. In a locale using 580 the ISO/IEC 646:1991 standard as the underlying codeset, the command: 581 582 .sp 583 .in +2 584 .nf 585 example% \fBprintf "%d\en" 3 +3 -3 \e'3 \e"+3 "'-3"\fR 586 .fi 587 .in -2 588 .sp 589 590 .sp 591 .LP 592 produces: 593 594 .sp 595 596 .sp 597 .TS 598 box; 599 l l 600 l l . 601 \fB3\fR Numeric value of constant 3 602 \fB3\fR Numeric value of constant 3 603 \fB\(mi3\fR Numeric value of constant \(mi3 604 \fB51\fR T{ 605 Numeric value of the character `3' in the ISO/IEC 646:1991 standard codeset 606 T} 607 \fB43\fR T{ 608 Numeric value of the character `+' in the ISO/IEC 646:1991 standard codeset 609 T} 610 \fB45\fR T{ 611 Numeric value of the character `\(mi' in the SO/IEC 646:1991 standard codeset 612 T} 613 .TE 614 615 .sp 616 .LP 617 In a locale with multi-byte characters, the value of a character is intended to 618 be the value of the equivalent of the \fBwchar_t\fR representation of the 619 character. 620 621 .sp 622 .LP 623 If an argument operand cannot be completely converted into an internal value 624 appropriate to the corresponding conversion specification, a diagnostic message 625 is written to standard error and the utility does exit with a zero exit status, 626 but continues processing any remaining operands and writes the value 627 accumulated at the time the error was detected to standard output. 628 629 .LP 630 \fBExample 6 \fRAlternative floating point representation 1 631 .sp 632 .LP 633 The \fBprintf\fR utility supports an alternative floating point representation 634 (see \fBprintf\fR(3C) entry for the "\fB%a\fR"/"\fB%A\fR"), which allows the 635 output of floating-point values in a format that avoids the usual base16 to 636 base10 rounding errors. 637 638 .sp 639 .in +2 640 .nf 641 example% printf "%a\en" 2 3.1 NaN 642 .fi 643 .in -2 644 .sp 645 646 .sp 647 .LP 648 produces: 649 650 .sp 651 .in +2 652 .nf 653 0x1.0000000000000000000000000000p+01 654 0x1.8ccccccccccccccccccccccccccdp+01 655 nan 656 .fi 657 .in -2 658 .sp 659 660 .LP 661 \fBExample 7 \fRAlternative floating point representation 2 662 .sp 663 .LP 664 The following example shows two different representations of the same 665 floating-point value. 666 667 .sp 668 .in +2 669 .nf 670 example% x=2 ; printf "%f == %a\en" x x 671 .fi 672 .in -2 673 .sp 674 675 .sp 676 .LP 677 produces: 678 679 .sp 680 .in +2 681 .nf 682 2.000000 == 0x1.0000000000000000000000000000p+01 683 .fi 684 .in -2 685 .sp 686 687 .LP 688 \fBExample 8 \fROutput of unicode values 689 .sp 690 .LP 691 The following command will print the EURO unicode symbol (code-point 0x20ac). 692 693 .sp 694 .in +2 695 .nf 696 example% LC_ALL=en_US.UTF-8 printf "\u[20ac]\en" 697 .fi 698 .in -2 699 .sp 700 701 .sp 702 .LP 703 produces: 704 705 .sp 706 .in +2 707 .nf 708 <euro> 709 .fi 710 .in -2 711 .sp 712 713 .sp 714 .LP 715 where "<euro>" represents the EURO currency symbol character. 716 717 .LP 718 \fBExample 9 \fRConvert unicode character to unicode code-point value 719 .sp 720 .LP 721 The following command will print the hexadecimal value of a given character. 722 723 .sp 724 .in +2 725 .nf 726 example% export LC_ALL=en_US.UTF-8 727 example% printf "%x\en" "'<euro>" 728 .fi 729 .in -2 730 .sp 731 732 .sp 733 .LP 734 where "<euro>" represents the EURO currency symbol character (code-point 735 0x20ac). 736 737 .sp 738 .LP 739 produces: 740 741 .sp 742 .in +2 743 .nf 744 20ac 745 .fi 746 .in -2 747 .sp 748 749 .LP 750 \fBExample 10 \fRPrint the numeric value of an ASCII character 751 .sp 752 .in +2 753 .nf 754 example% printf "%d\en" "'A" 755 .fi 756 .in -2 757 .sp 758 759 .sp 760 .LP 761 produces: 762 763 .sp 764 .in +2 765 .nf 766 65 767 .fi 768 .in -2 769 .sp 770 771 .LP 772 \fBExample 11 \fRPrint the language-independent date and time format 773 .sp 774 .LP 775 To print the language-independent date and time format, the following statement 776 could be used: 777 778 .sp 779 .in +2 780 .nf 781 example% printf "format" weekday month day hour min 782 .fi 783 .in -2 784 .sp 785 786 .sp 787 .LP 788 For example, 789 790 .sp 791 .in +2 792 .nf 793 $ printf format "Sunday" "July" 3 10 2 794 .fi 795 .in -2 796 .sp 797 798 .sp 799 .LP 800 For American usage, format could be the string: 801 802 .sp 803 .in +2 804 .nf 805 "%s, %s %d, %d:%.2d\en" 806 .fi 807 .in -2 808 .sp 809 810 .sp 811 .LP 812 producing the message: 813 814 .sp 815 .in +2 816 .nf 817 Sunday, July 3, 10:02 818 .fi 819 .in -2 820 .sp 821 822 .sp 823 .LP 824 Whereas for EU usage, format could be the string: 825 826 .sp 827 .in +2 828 .nf 829 "%1$s, %3$d. %2$s, %4$d:%5$.2d\en" 830 .fi 831 .in -2 832 .sp 833 834 .sp 835 .LP 836 Note that the '$' characters must be properly escaped, such as 837 838 .sp 839 .in +2 840 .nf 841 "%1\$s, %3\$d. %2\$s, %4\$d:%5\$.2d\en" in this case 842 .fi 843 .in -2 844 .sp 845 846 .sp 847 .LP 848 producing the message: 849 850 .sp 851 .in +2 852 .nf 853 Sunday, 3. July, 10:02 854 .fi 855 .in -2 856 .sp 857 858 .SH ENVIRONMENT VARIABLES 859 .sp 860 .LP 861 See \fBenviron\fR(5) for descriptions of the following environment variables 862 that affect the execution of \fBprintf\fR: \fBLANG\fR, \fBLC_ALL\fR, 863 \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, \fBLC_NUMERIC\fR, and \fBNLSPATH\fR. 864 .SH EXIT STATUS 865 .sp 866 .LP 867 The following exit values are returned: 868 .sp 869 .ne 2 870 .na 871 \fB\fB0\fR\fR 872 .ad 873 .RS 6n 874 Successful completion. 875 .RE 876 877 .sp 878 .ne 2 879 .na 880 \fB\fB>0\fR\fR 881 .ad 882 .RS 6n 883 An error occurred. 884 .RE 885 886 .SH ATTRIBUTES 887 .sp 888 .LP 889 See \fBattributes\fR(5) for descriptions of the following attributes: 890 .SS "/usr/bin/printf" 891 .sp 892 893 .sp 894 .TS 895 box; 896 c | c 897 l | l . 898 ATTRIBUTE TYPE ATTRIBUTE VALUE 899 _ 900 CSI Enabled 901 _ 902 Interface Stability Committed 903 _ 904 Standard See \fBstandards\fR(5). 905 .TE 906 907 .SS "ksh93" 908 .sp 909 910 .sp 911 .TS 912 box; 913 c | c 914 l | l . 915 ATTRIBUTE TYPE ATTRIBUTE VALUE 916 _ 917 Interface Stability Uncommitted 918 .TE 919 920 .SH SEE ALSO 921 .sp 922 .LP 923 \fBawk\fR(1), \fBbc\fR(1), \fBdate\fR(1), \fBecho\fR(1), \fBksh93\fR(1), 924 \fBprintf\fR(3C), \fBstrtod\fR(3C), \fBstrtol\fR(3C), \fBstrtoul\fR(3C), 925 \fBattributes\fR(5), \fBenviron\fR(5), \fBformats\fR(5), \fBstandards\fR(5) 926 .SH NOTES 927 .sp 928 .LP 929 Using format specifiers (characters following '%') which are not listed in the 930 \fBprintf\fR(3C) or this manual page will result in undefined behavior. 931 .sp 932 .LP 933 Using escape sequences (the character following a backslash ('\e')) which are 934 not listed in the \fBprintf\fR(3C) or this manual page will result in undefined 935 behavior. 936 .sp 937 .LP 938 Floating-point values follow C99, XPG6 and IEEE 754 standard behavior and can 939 handle values the same way as the platform's |\fBlong double\fR| datatype. 940 .sp 941 .LP 942 Floating-point values handle the sign separately which allows signs for values 943 like NaN (for example, -nan), Infinite (for example, -inf) and zero (for 944 example, -0.0).