vuoi
o PayPal
tutte le volte che vuoi
ASYNCHRONOUS EVENTS
Default.STDOUT
See the EXTENDED DESCRIPTION section.
STDERR
Used only for diagnostic messages.
OUTPUT FILES
None.
EXTENDED DESCRIPTION
The format operand will be used as the format string described in the specification,XBD Filewith the following exceptions:
Format Notation
A character in the format string, in any context other than a flag of a conversionspecification, will be treated as an ordinary character that is copied to the output.
In addition to the escape sequences shown in the specification,XBD File Format(\\, \a, \b, \f, \n, \r, \t, \v), where ddd is a one-, two- or three-digit octalNotation \ddd,number, will be written as a byte with the numeric value specified by the octal number.
The implementation will not precede or follow output from the d or u conversionspecifications with blank characters not specified by the format operand.
The implementation will not precede output from the o conversion specification withzeros not specified by the format operand.
The e, E, f,
g and G conversion specifications need not be supported.
An additional conversion character, b, will be supported as follows. The argument will be taken to be a string that may contain backslash-escape sequences. The following backslash-escape sequences will be supported:
- the escape sequences listed in the specification, (\\, \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 \0ddd,
- \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 unspecified.
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 written. 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 behavior is unspecified.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 standard output.
EXIT STATUS
The following exit values are returned:
- 0 Successful completion.
- >0 An error occurred.
CONSEQUENCES OF ERRORS
Default.
3 di 6 10/06/2010 16:17printf
http://www.opengroup.org/onlinepubs/007908799/xcu/printf.html
APPLICATION USAGE
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 precision. (This printf utility cannot really be used to format precision.) Implementations are encouraged to support the floating-point conversions as an extension.
Note that this printf utility, like the specification printf() function on which it is based, XSH makes no special provision for dealing with multi-byte characters when using the %c conversion specification or when a precision is specified in a %b or %s 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 directlyin the format operand using shell variable substitution. Implementations can also provide thisfeature as an extension if they so choose.Hexadecimal character constants as defined in the ISO C standard are not recognised in theformat operand because there is no consistent way to detect the end of the constant. Octalcharacter constants are limited to, at most, three octal digits, but hexadecimal characterconstants 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 hexadecimalcharacter to be written. In the shell, concatenation occurs before the printf utility has achance 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%ba 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 a character.
EXAMPLES
To alert the user and then print and read a series of prompts:
printf "\aPlease fill in the following: \nName: "read nameprintf "Phone number: "read phone
To read out a list of right and wrong answers from a file, calculate the percentage correctly, and print them out.
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 printf http://www.opengroup.org/onlinepubs/007908799/xcu/printf.html while read right wrong ; do percent=$(echo "scale=1;($right*100)/($right+$wrong)" | bc) printf "%2d right\t%2d wrong\t(%s%%)\n" $right $wrong $percent done < database_file
The command:
printf "%5d%4d\n" 1 21 321 4321 54321
produces:
1 21 321 4321 54321 0
Note that the format operand is used three times to print all of the given strings and that a 0 was supplied by printf to satisfy the last conversion specification.
%4d
The printf utility is required to notify the user when conversion errors are detected while producing numeric output; thus, the following results would be expected on an implementation with 32-bit twos-complement integers when is specified as the format %d operand:
Argument Standard Diagnostic Output Output 5a 5 printf: "5a" not
completely converted9999999999 2147483647 printf: "9999999999" arithmetic overflow-9999999999 -2147483648 printf: "-9999999999" arithmetic overflowABC 0 printf: "ABC" expected numeric value
The diagnostic message format is not specified, but these examples convey the type of information that should be reported. Note that the value shown on standard output is what would be expected as the return value from the specification function strtol(). A similar XSH correspondence exists between and strtoul() and and (if the implementation %u %e, %f %g supports floating-point conversions) and strtod().
In a locale using the ISO/IEC 646:1991 standard as the underlying codeset, the command:
printf "%d\n" 3 +3 -3 \'3 \"+3 "\'-3\"
produces:
3 Numeric value of constant 3
3 Numeric value of constant 3
-3 Numeric value of constant -3
51 Numeric value of the character `3' in the ISO/IEC 646:1991 standard codeset
43 Numeric value of the character
+' in the ISO/IEC 646:1991 standardcodeset45
Numeric value of the character `-' in the ISO/IEC 646:1991 standardcodeset5
di 6 10/06/2010 16:17