The format string consists of ordinary characters (everything except
'%'), which are passed through unchanged, and formatting directives,
which have the following form:
% flag* vector? width? precision? type
? mean 0 or more and 0 or 1 of the preceding item, respectively.)
- prefix positive numbers with a space
- prefix positive numbers with a plus sign (overrides space if both are present)
- left-justify within the field
- pad with zeroes on the left, not spaces
- prefix binary numbers with
0B, octal numbers with
0Oand hexadecimal numbers with
The vector flag
printf to format each character in the string
argument according to the current directive, then joins the results with a
separator that defaults to
*v is used, the separator is
taken from the argument list (use e.g.
want no separator).
printf "%*v.2x" "" str
The width is either a decimal integer or
*, in which case the width is
taken from the argument list (this argument must be an integer). It
specifies the minimum width for this field. Shorter values are padded on
the left with spaces (but this can be changed by the
- flags). If
the width taken from the argument list is negative, it behaves as if the
- flag was specified.
The precision consists of a
. followed by digits or a
* (see the
description of width above). The effects depend on the format type:
- for floating point formats, this specifies the number of digits after the decimal point
- for string formats, this is the maximum number of characters to appear (longer strings are truncated)
- for integer formats, this is the minimum number of digits to appear in the output; shorter values are zero-padded
- A percent sign. No argument is consumed.
- A character. If the argument is an integer, it is converted with
- A string.
- A decimal integer.
- An unsigned decimal integer.
- A binary integer.
b, but using a
- An octal integer.
o, but using a
- A hexadecimal integer.
x, but using uppercase letters.
- A floating point number in scientific notation.
e, but using an uppercase
- A floating point number in fixed decimal notation.
- A floating point number in
g, but using an uppercase
- A generic format; it behaves like
%g, depending on the argument type.