HP-UX Reference (11i v1 05/09) - 1 User Commands N-Z (vol 2)
p
printf(1) printf(1)
NAME
printf - format and print arguments
SYNOPSIS
printf format [ arg ... ]
DESCRIPTION
printf writes formatted arguments to the standard output. The arg arguments are formatted under con-
trol of the format operand.
format is a character string patterned after the formatting conventions of printf(3S), and contains the fol-
lowing types of objects:
characters Characters that are not escape sequences or conversion specifications (as
described below) are copied to standard output.
escape sequences These are interpreted as non-graphic characters:
\a alert
\b backspace
\c print line without appending a new-line
\f form-feed
\n new-line
\r carriage return
\t tab
\v vertical tab
\’ single quote character
\\ backslash
\n the 8-bit character whose ASCII code is the 1-, 2-, 3-, or 4-digit octal
number n, whose first character must be a zero.
conversion specification
Specifies the output format of each argument ( see below).
Arguments following format are interpreted as strings if the corresponding format is either
c or s;
otherwise they are treated as constants.
Conversion Specifications
Each conversion specification is introduced by the percent character
%. After the %
character, the follow-
ing can appear in the sequence indicated:
flags Zero or more flags, in any order, which modify the meaning of the conversion
specification. The flag characters and their meanings are:
- The result of the conversion is left-justified within the field.
+ The result of a signed conversion always begins with a sign, + or -.
<space> If the first character of a signed conversion is not a sign, a space charac-
ter is prefixed to the result. This means that if the space flag and
+ flag
both appear, the space flag is ignored.
# The value is to be converted to an ‘‘alternate form’’. For c, d, i, u, and
s conversions, this flag has no effect. For o conversion, it increases the
precision to force the first digit of the result to be a zero. For x or X
conversion, a non-zero result has 0x or 0X prefixed to it. For e, E, f,
g, and G conversions, the result always contains a radix character, even
if no digits follow the radix character. For g and G conversions, trailing
zeros are not removed from the result, contrary to usual behavior.
field width An optional string of decimal digits to specify a minimum field width. For an output
field, if the converted value has fewer characters than the field width, it is padded on the
left (or right, if the left-adjustment flag, - has been given) to the field width.
precision The precision specifies the minimum number of digits to appear for the d, o, i, u, x,orX
conversions (the field is padded with leading zeros), the number of digits to appear after
the radix character for the e and f conversions, the maximum number of significant
digits for the g conversion, or the maximum number of characters to be printed from a
string in s conversion. The precision takes the form of a period . followed by a decimal
Section 1−−782 Hewlett-Packard Company − 1 − HP-UX 11i Version 1: September 2005