printf.1 (98cdf45a92ada981b8c4e22ac69956b4139b1341) | printf.1 (598f4ceed9327d2d6c2325dd67cae3aa06f7fea6) |
---|---|
1'\" te | 1'\" te |
2.\" Copyright 2014 Garrett D'Amore <garrett@damore.org> |
|
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 | 3.\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved 4.\" Copyright 1992, X/Open Company Limited All Rights Reserved 5.\" 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" | 6.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for 7.\" permission to reproduce portions of its copyrighted documentation. 8.\" Original documentation from The Open Group can be obtained online at 9.\" http://www.opengroup.org/bookstore/. 10.\" The Institute of Electrical and Electronics Engineers and The Open Group, 11.\" have given us permission to reprint portions of their documentation. In the 12.\" following statement, the phrase "this text" refers to portions of the 13.\" system documentation. Portions of this text are reprinted and reproduced in 14.\" electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 15.\" Edition, Standard for Information Technology -- Portable Operating System 16.\" Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright 17.\" (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, 18.\" Inc and The Open Group. In the event of any discrepancy between these 19.\" versions and the original IEEE and The Open Group Standard, the original 20.\" IEEE and The Open Group Standard is the referee document. The original 21.\" Standard can be obtained online at 22.\" http://www.opengroup.org/unix/online.html. 23.\" This notice shall appear on any product containing this material. 24.\" The contents of this file are subject to the terms of the Common 25.\" Development and Distribution License (the "License"). You may not use this 26.\" file except in compliance with the License. 27.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or 28.\" http://www.opensolaris.org/os/licensing. See the License for the specific 29.\" language governing permissions and limitations under the License. 30.\" When distributing Covered Code, include this CDDL HEADER in each file and 31.\" include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, 32.\" add the following below this CDDL HEADER, with the fields enclosed by 33.\" brackets "[]" replaced with your own identifying information: 34.\" Portions Copyright [yyyy] [name of copyright owner] 35.TH PRINTF 1 "May 11, 2014" |
14.SH NAME 15printf \- write formatted output 16.SH SYNOPSIS 17.SS "/usr/bin/printf" 18.LP 19.nf 20\fBprintf\fR \fIformat\fR [\fIargument\fR]... 21.fi --- 63 unchanged lines hidden (view full) --- 85.el o 86The program does not precede output from the \fBo\fR conversion specification 87with zeros not specified by the \fIformat\fR operand. 88.RE 89.RS +4 90.TP 91.ie t \(bu 92.el o | 36.SH NAME 37printf \- write formatted output 38.SH SYNOPSIS 39.SS "/usr/bin/printf" 40.LP 41.nf 42\fBprintf\fR \fIformat\fR [\fIargument\fR]... 43.fi --- 63 unchanged lines hidden (view full) --- 107.el o 108The program does not precede output from the \fBo\fR conversion specification 109with zeros not specified by the \fIformat\fR operand. 110.RE 111.RS +4 112.TP 113.ie t \(bu 114.el o |
115The argument used for the conversion character (or width or precision 116parameters, see below) may be taken from the \fIn\fRnth argument instead 117of the next unused argument, by specifying \fIn\fR\fB$\fR immediately following 118the \fB%\fR character, or the \fB*\fR character (for width or precision 119arguments). 120If \fIn\fR\fB$\fR appears in any conversions in the format string, 121then it must be used for all conversions, including any variable width or 122precision specifiers. 123.RE 124.RS +4 125.TP 126.ie t \(bu 127.el o 128The special character \fB*\fR may be used instead of a string of decimal digits 129to indicate a minimum field width or a precision. In this case the next 130available argument is used (or the \fIn\fRth if the form \fIn\fR\fB$\fR is 131used), treating its value as a decimal string. 132.RE 133.RS +4 134.TP 135.ie t \(bu 136.el o |
|
93An additional conversion character, \fBb\fR, is supported as follows. The 94argument is taken to be a string that can contain backslash-escape sequences. 95The following backslash-escape sequences are supported: 96.RS +4 97.TP 98.ie t \(bu 99.el o 100the escape sequences listed on the \fBformats\fR(5) manual page (\fB\e\e\fR, --- 24 unchanged lines hidden (view full) --- 125number of bytes indicated by the precision specification is reached. If the 126precision is omitted, it is taken to be infinite, so all bytes up to the end of 127the converted string are written. For each specification that consumes an 128argument, the next argument operand is evaluated and converted to the 129appropriate type for the conversion as specified below. The \fIformat\fR 130operand is reused as often as necessary to satisfy the argument operands. Any 131extra \fBc\fR or \fBs\fR conversion specifications are evaluated as if a null 132string argument were supplied; other extra conversion specifications are | 137An additional conversion character, \fBb\fR, is supported as follows. The 138argument is taken to be a string that can contain backslash-escape sequences. 139The following backslash-escape sequences are supported: 140.RS +4 141.TP 142.ie t \(bu 143.el o 144the escape sequences listed on the \fBformats\fR(5) manual page (\fB\e\e\fR, --- 24 unchanged lines hidden (view full) --- 169number of bytes indicated by the precision specification is reached. If the 170precision is omitted, it is taken to be infinite, so all bytes up to the end of 171the converted string are written. For each specification that consumes an 172argument, the next argument operand is evaluated and converted to the 173appropriate type for the conversion as specified below. The \fIformat\fR 174operand is reused as often as necessary to satisfy the argument operands. Any 175extra \fBc\fR or \fBs\fR conversion specifications are evaluated as if a null 176string argument were supplied; other extra conversion specifications are |
133evaluated as if a zero argument were supplied. If the \fIformat\fR operand | 177evaluated as if a zero argument were supplied. 178.sp 179When there are more argument operands than format specifiers, and the 180format includes \fIn\fR\fB$\fR position indicators, then the format is 181reprocessed from the beginning as above, but with the argument list starting 182from the next argument after the highest \fIn\fRth argument previously 183encountered. 184.sp 185If the \fIformat\fR operand |
134contains no conversion specifications and \fIargument\fR operands are present, 135the results are unspecified. If a character sequence in the \fIformat\fR 136operand begins with a \fB%\fR character, but does not form a valid conversion 137specification, the behavior is unspecified. 138.RE 139 140.sp 141.ne 2 --- 239 unchanged lines hidden (view full) --- 381.el o 382The escape sequence \fB\eC[.\fR\fIname\fR\fB\&.]\fR expands to the collating 383element \fIname\fR. 384.RE 385.RS +4 386.TP 387.ie t \(bu 388.el o | 186contains no conversion specifications and \fIargument\fR operands are present, 187the results are unspecified. If a character sequence in the \fIformat\fR 188operand begins with a \fB%\fR character, but does not form a valid conversion 189specification, the behavior is unspecified. 190.RE 191 192.sp 193.ne 2 --- 239 unchanged lines hidden (view full) --- 433.el o 434The escape sequence \fB\eC[.\fR\fIname\fR\fB\&.]\fR expands to the collating 435element \fIname\fR. 436.RE 437.RS +4 438.TP 439.ie t \(bu 440.el o |
389The escape sequence \fB\ex{hex}\fRexpands to the character corresponding to the 390hexadecimal value \fBhex\fR. | 441The escape sequence \fB\ex{hex}\fR expands to the character corresponding to 442the hexadecimal value \fBhex\fR. |
391.RE 392.RS +4 393.TP 394.ie t \(bu 395.el o 396The format modifier flag = can be used to center a field to a specified width. 397When the output is a terminal, the character width is used rather than the 398number of bytes. --- 27 unchanged lines hidden (view full) --- 426.LP 427If there are more \fIstring\fR operands than format specifiers, the format 428string is reprocessed from the beginning. If there are fewer \fIstring\fR 429operands than format specifiers, then \fIstring\fR specifiers are treated as if 430empty strings were supplied, numeric conversions are treated as if \fB0\fR was 431supplied, and time conversions are treated as if \fBnow\fR was supplied. 432.sp 433.LP | 443.RE 444.RS +4 445.TP 446.ie t \(bu 447.el o 448The format modifier flag = can be used to center a field to a specified width. 449When the output is a terminal, the character width is used rather than the 450number of bytes. --- 27 unchanged lines hidden (view full) --- 478.LP 479If there are more \fIstring\fR operands than format specifiers, the format 480string is reprocessed from the beginning. If there are fewer \fIstring\fR 481operands than format specifiers, then \fIstring\fR specifiers are treated as if 482empty strings were supplied, numeric conversions are treated as if \fB0\fR was 483supplied, and time conversions are treated as if \fBnow\fR was supplied. 484.sp 485.LP |
486When there are more argument operands than format specifiers, and the 487format includes \fIn\fR\fB$\fR position indicators, then the format is 488reprocessed from the beginning as above, but with the argument list starting 489from the next argument after the highest \fIn\fRth argument previously 490encountered. 491.sp 492.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 440The \fBprintf\fR utility, like the \fBprintf\fR(3C) function on which it is 441based, makes no special provision for dealing with multi-byte characters when 442using the \fB%c\fR conversion specification. Applications should be extremely 443cautious using either of these features when there are multi-byte characters in 444the character set. 445.sp 446.LP | 493\fB/usr/bin/printf\fR is equivalent to \fBksh93\fR's \fBprintf\fR built-in and 494\fBprint -f\fR, which allows additional options to be specified. 495.SH USAGE 496.SS "/usr/bin/printf" 497.sp 498.LP 499The \fBprintf\fR utility, like the \fBprintf\fR(3C) function on which it is 500based, makes no special provision for dealing with multi-byte characters when 501using the \fB%c\fR conversion specification. Applications should be extremely 502cautious using either of these features when there are multi-byte characters in 503the character set. 504.sp 505.LP |
447Field widths and precisions cannot be specified as \fB*\fR. 448.sp 449.LP | |
450The \fB%b\fR conversion specification is not part of the ISO C standard; it has 451been added here as a portable way to process backslash escapes expanded in 452string operands as provided by the \fBecho\fR utility. See also the USAGE 453section of the \fBecho\fR(1) manual page for ways to use \fBprintf\fR as a 454replacement for all of the traditional versions of the \fBecho\fR utility. 455.sp 456.LP 457If an argument cannot be parsed correctly for the corresponding conversion --- 375 unchanged lines hidden (view full) --- 833 834.sp 835.LP 836Note that the '$' characters must be properly escaped, such as 837 838.sp 839.in +2 840.nf | 506The \fB%b\fR conversion specification is not part of the ISO C standard; it has 507been added here as a portable way to process backslash escapes expanded in 508string operands as provided by the \fBecho\fR utility. See also the USAGE 509section of the \fBecho\fR(1) manual page for ways to use \fBprintf\fR as a 510replacement for all of the traditional versions of the \fBecho\fR utility. 511.sp 512.LP 513If an argument cannot be parsed correctly for the corresponding conversion --- 375 unchanged lines hidden (view full) --- 889 890.sp 891.LP 892Note that the '$' characters must be properly escaped, such as 893 894.sp 895.in +2 896.nf |
841"%1\$s, %3\$d. %2\$s, %4\$d:%5\$.2d\en" in this case | 897"%1\e$s, %3\e$d. %2\e$s, %4\e$d:%5\e$.2d\en" in this case |
842.fi 843.in -2 844.sp 845 846.sp 847.LP 848producing the message: 849 --- 95 unchanged lines hidden --- | 898.fi 899.in -2 900.sp 901 902.sp 903.LP 904producing the message: 905 --- 95 unchanged lines hidden --- |