format specifications causes outputing of the next successive argument.
The arguments after the first are treated as strings if the corresponding format is c, b or s
; otherwise it is evaluated as a C language constant, except that:
- leading plus or minus sign is allowed.
- leading apostrophe or quote causes the value is the ASCII code of the next character.
format
is reused as often as necessary to satisfy the arguments.
Excess format specifications are evaluated with zero or null as values.
Escape sequences in backslash notation
\b backspace \t tab \f form-feed \v vertical tab \n new-line \r return
\' apostrohpe \\ backslash
\num
\0num Write an 8-bit character whose ASCII value is the 1-3 digit octal number num.
\a alert bell
\c Ignore remaining characters
format
is introduced by %
followed by, in order:
Zero or more flags:
- left adjustment
| 0 zero padding
A - overrides a 0
| + always output a sign
| space | space should be left before a positive number for a signed format. ( A + overrides a space)
| # alternate form:
o : leading zero.
| x (X ) : a non-zero has 0x (0X ) prepended .
| e, E, f, g, and G , the result always contains a decimal point otherwise a decimal appears if a digit follows.
| g G : trailing zeros are retained.
| ineffective for c , d and s
|
| | | | |
embedded specifications
Field Width:[www]
Output string will be blank-padded on the left
(or right, if the left-adjustment indicator has been given)
A leading zero is a flag, but an embedded zero is part of a field width.
A field width of * uses the next argument for the field width
| Precision:[.[pp] |
Number of digits to appear after the decimal point, for e and f formats
The maximum number of characters from a string.
default : zero;
A precision of * uses the next argument for the precision.
|
xfegadioucsb
XFEGA
Type of format to use. The uppercase formats produce uppercase output .
For example: printf " %E %e \n" "1.2" "3.4"
1.200000E+00 3.400000e+00
The floating-point formats (fFeEgGaA ) prefixed by an L requests Long precision
| | |
Format characters :
d i
u Xx o The argument is output as a
signed decimal
unsigned decimal, unsigned hexadecimal or unsigned octal.
| f F [-]ddd.ddd where the number of d's after the decimal
point is the precision specification for the argument.
Default is 6. If the precision is explicitly 0, no digits and no decimal point are output.
The infinity and NaN (NotANumber) are output as inf and nan
| e E e [-d.ddd+-dd] where one digit before the
decimal point and the number after is the precision specification ; default is 6 digits are produced.
The infinity and NaN (NotANumber) are output as inf and nan
| g G f (F) or e (E) whichever gives full precision in minimum space.
| a A [-h.hhh+-pd] where there is one digit before the hexadecimal point and
the number after is equal to the precision specification;
when the precision is missing, enough digits are produced to convey the argument's exact double-precision floating-point representation.
The infinity and NaN (NotANumber) are output as inf and nan
| c only first character of argument is output
| s Characters from the string argument are output until the end is reached or until the number of characters indicated by the precision specification is reached;
if the precision is 0 or missing, all characters in the string are output.
| b As for s , but interpret character escapes in backslash notation in the string argument.
| % output a % ; no argument is used.
| | | | | | | | |
|
The decimal point character is defined in the program's locale (category LC_NUMERIC).
A non-existent or small field width does not truncate a field;
Padding takes place only if the field width exceeds the actual width.
Exit status
0 on success
>0 if an error occurs.
1 missing format character, invalid format character
Compatibility
Numeric formats, not beginning with a digit, are not converted to the ASCII code of the first character
See
echo(1), printf(3)
BUGS
Since the floating point numbers are translated from ASCII to floating-point and then back again,
floating-point precision may be lost. (By default, the number is translated to an IEEE-754 double-precision value before being printed. The L modifier may produce additional precision, depending on the
hardware platform.)
ANSI hexadecimal character constants were deliberately not provided.
\000
is the string terminator. In the argument for b
format, the
argument will be truncated at the \000 character.
Multibyte characters are not recognized in format strings (this is only a problem if `%' can appear
inside a multibyte character).
Parsing of - arguments is also somewhat different from printf(3) where unknown arguments are simply
printed instead of being flagged as errors.