Sistemi operativi - Syscall printf
\a, \b, \f, \n, \r, \t, \v), which will be converted to the characters they represent
where ddd is a zero-, one-, two- or three-digit octal number that will be
converted to a byte with the numeric value specified by the octal number
\c, which will not be written and will cause printf to ignore any remaining
characters in the string operand containing it, any remaining string operands and
any additional characters in the format operand.
The interpretation of a backslash followed by any other sequence of characters is
Bytes from the converted string will be written until the end of the string or the number
of bytes indicated by the precision specification is reached. If the precision is omitted,
it will be taken to be infinite, so all bytes up to the end of the converted string will be
For each specification that consumes an argument, the next argument operand will be
evaluated and converted to the appropriate type for the conversion as specified below.
The format operand will be reused as often as necessary to satisfy the argument
operands. Any extra c or s conversion specifications will be evaluated as if a null string
argument were supplied; other extra conversion specifications will be evaluated as if a
zero argument were supplied. If the format operand contains no conversion
specifications and argument operands are present, the results are unspecified.
If a character sequence in the format operand begins with a "%" character, but does
not form a valid conversion specification, the behaviour is unspecified.
The argument operands will be treated as strings if the corresponding conversion character is
b, c or s; otherwise, it will be evaluated as a C constant, as described by the ISO C standard,
with the following extensions:
A leading plus or minus sign will be allowed.
If the leading character is a single- or double-quote, the value will be the numeric value
in the underlying codeset of the character following the single- or double-quote.
If an argument operand cannot be completely converted into an internal value appropriate to
the corresponding conversion specification, a diagnostic message will be written to standard
error and the utility will not exit with a zero exit status, but will continue processing any
remaining operands and will write the value accumulated at the time the error was detected to
The following exit values are returned:
0 Successful completion.
>0 An error occurred.
CONSEQUENCES OF ERRORS
3 di 6 10/06/2010 16:17
The floating-point formatting conversion specifications of printf() are not required because
all arithmetic in the shell is integer arithmetic. The awk utility performs floating-point
calculations and provides its own function. The bc utility can perform arbitrary-
precision floating-point arithmetic, but does not provide extensive formatting capabilities.
bc output; it does not support arbitrary
(This printf utility cannot really be used to format
precision.) Implementations are encouraged to support the floating-point conversions as an
Note that this printf utility, like the specification printf() function on which it is based,
makes no special provision for dealing with multi-byte characters when using the %c
conversion specification or when a precision is specified in a or conversion
specification. Applications should be extremely cautious using either of these features when
there are multi-byte characters in the character set.
Field widths and precisions cannot be specified as "*" since the "*" can be replaced directly
in the format operand using shell variable substitution. Implementations can also provide this
feature as an extension if they so choose.
Hexadecimal character constants as defined in the ISO C standard are not recognised in the
format operand because there is no consistent way to detect the end of the constant. Octal
character constants are limited to, at most, three octal digits, but hexadecimal character
constants are only terminated by a non-hex-digit character. In the ISO C standard, the ##
concatenation operator can be used to terminate a constant and follow it with a hexadecimal
character to be written. In the shell, concatenation occurs before the printf utility has a
chance to parse the end of the hexadecimal constant.
The conversion specification is not part of the ISO C standard; it has been added here as
a portable way to process backslash escapes expanded in string operands as provided by the
echo utility. See also the APPLICATION USAGE section of echo for ways to use printf as a
replacement for all of the traditional versions of the echo utility.
If an argument cannot be parsed correctly for the corresponding conversion specification, the
printf utility is required to report an error. Thus, overflow and extraneous characters at the
end of an argument being used for a numeric conversion are to be reported as errors.
It is not considered an error if an argument operand is not completely used for a c or s
conversion or if a string operand's first or second character is used to get the numeric value of
To alert the user and then print and read a series of prompts:
printf "\aPlease fill in the following: \nName: "
printf "Phone number: "
To read out a list of right and wrong answers from a file, calculate the percentage correctly,
and print them out. The numbers are right-justified and separated by a single tab character.
The percentage is written to one decimal place of accuracy:
4 di 6 10/06/2010 16:17
+1 anno fa
I contenuti di questa pagina costituiscono rielaborazioni personali del Publisher N. A. di informazioni apprese con la frequenza delle lezioni di Sistemi operativi e studio autonomo di eventuali libri di riferimento in preparazione dell'esame finale o della tesi. Non devono intendersi come materiale ufficiale dell'università Napoli Federico II - Unina o del prof Cotroneo Domenico.
Acquista con carta o conto PayPal
Scarica il file tutte le volte che vuoi
Paga con un conto PayPal per usufruire della garanzia Soddisfatto o rimborsato