SYNOPSIS
printf format [argument ...]
DESCRIPTION
The printf command writes a string to standard output with a controlled
format. It is essentially a utility variant of the `C' language func-
tion printf(3).
Most characters in the format string are simply copied. The only
exceptions are the backslash `\' and percent `%' characters.
The backslash `\' character in the format string serves as an escape
for the following character. The sequences `\a' (alert), `\b'
(backspace), `\f' (formfeed), `\n' (newline), `\r' (carriage return),
`\t' (tabulator), and `\v' (vertical tabulator) cause the corresponding
control characters to be printed. The sequence `\nnn', where nnn is a
one-, two-, or three-digit octal number, cause the character (byte)
with the corresponding number to be printed. `\\' prints the backslash
character itself.
The percent `%' character in the format string introduces a conversion
specification consisting of up to five parts, of which the first four
are optional:
position A positive decimal integer followed by a dollar `$' char-
acter that specifies the argument to be used instead of
the next unused one for the following conversions.
flags Zero or more of
- left-justify the field
+ always include a sign when printing a number
<space> prefix the result by a space if there is no sign
# alternate format
0 pad numbers with leading zeros
field width A decimal number giving the minimum width of the output
printed. The output is padded if necessary, as con-
trolled by the flags described above. By default, no
padding is performed. If the field width is `*', it is
taken from the next unused argument.
precision A dot `.', followed by a decimal number giving the mini-
mum digits written for integer numeric conversions, the
minumum digits after the radix character for floating-
point numeric conversions, or maximum bytes written for
string conversions. If the precisision is `.*', it is
taken from the next unused argument.
specifier A character controlling the type of the conversion per-
formed:
s The next unused argument is written as a plain
string.
u The next unused argument is written as an unsigned
decimal number.
x The next unused argument is written as a hexadecimal
number, using lowercase characters. With the `#'
flag, it is prefixed by `0x'.
X The next unused argument is written as a hexadecimal
number, using uppercase characters. With the `#'
flag, it is prefixed by `0X'.
f The next unused argument is written as a floating-
point number in the style `[-]nnn.nnn'.
e The next unused argument is written as a floating-
point number in the style `[-]n.nnne[+|-]nn'.
E The next unused argument is written as a floating-
point number in the style `[-]n.nnnE[+|-]nn'.
g The next unused argument is written as a floating-
point number like an integer if there is no frac-
tional part, as described for `f' if the exponent is
small, or as described for `g' if the exponent is
large.
G The next unused argument is written as a floating-
point number like an integer if there is no frac-
tional part, as described for `f' if the exponent is
small, or as described for `G' if the exponent is
large.
% A percent character is printed. No argument is con-
sumed.
If the argument for the numeric specifiers starts with a single- or
double quote (`'c' or `"c'), the numeric value of the following charac-
ter (byte sequence) in the current character encoding is used.
If the format string consumes at least an argument, no format specifi-
cation contains a position part, but there are still unused arguments
after the entire format string has been evaluated once, it is evaluated
repeatedly until all arguments are consumed. Missing arguments default
to the empty string for string conversions, and to zero if a numeric
value is expected.
ENVIRONMENT VARIABLES
LANG, LC_ALL
See locale(7).
LC_CTYPE
Determines the mapping of bytes to characters for `'c' and `"c'.
SEE ALSO
echo(1), printf(3)
Heirloom Toolchest 7/17/05 PRINTF(1)
Man(1) output converted with
man2html