Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
printf(1)		    General Commands Manual		     printf(1)

NAME
       printf -	format and print arguments

SYNOPSIS
       format [arg ...]

DESCRIPTION
       writes  formatted  arguments to the standard output.  The arg arguments
       are formatted under control of the format operand.

       format is a character string patterned after the	formatting conventions
       of printf(3S), and contains the following types of objects:

	      characters	  Characters  that are not escape sequences or
				  conversion specifications (as	described  be-
				  low) are copied to standard output.

	      escape sequences	  These	are interpreted	as non-graphic charac-
				  ters:

				       alert
				       backspace
				       form-feed
				       new-line
				       carriage	return
				       tab
				       vertical	tab
				       single quote character
				       backslash
				       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 or	otherwise they are treated  as
	      constants.

   Conversion Specifications
       Each  conversion	 specification	is introduced by the percent character
       After the character, the	following can appear  in  the  sequence	 indi-
       cated:

	      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
					 character  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
					 and conversions, this flag has	no ef-
					 fect.	For conversion,	 it  increases
					 the  precision	 to  force  the	 first
					 digit of the result  to  be  a	 zero.
					 For  or conversion, a non-zero	result
					 has or	prefixed to it.	 For and  con-
					 versions,  the	result always contains
					 a radix character, even if no	digits
					 follow	 the radix character.  For and
					 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  or  conversions  (the  field  is
			  padded  with leading zeros), the number of digits to
			  appear after the radix character for the and conver-
			  sions,  the maximum number of	significant digits for
			  the 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  digit  string.   A  null  digit  string  is
			  treated as a zero.

	      conversion characters
			  A conversion character indicates the type of conver-
			  sion to be applied:

			       The  integer argument is	printed	a signed deci-
			       mal
				       or unsigned octal unsigned  decimal  or
				       unsigned	 hexadecimal  notation and The
				       conversion uses the numbers and letters
				       and the conversion uses the numbers and
				       letters The precision component of  the
				       argument	 specifies  the	minimum	number
				       of digits to appear.  If	the value  be-
				       ing  converted  can  be	represented in
				       fewer digits than the  specified	 mini-
				       mum,  it	 is  expanded with leading ze-
				       roes.  The default precision is 1.  The
				       result  of converting a zero value with
				       a precision of 0	is no characters.

			       The floating-point number argument
				       is printed in decimal notation  in  the
				       style  ,	where the number of digits af-
				       ter the radix character,	 is  equal  to
				       the  precision  specification.	If the
				       precision is omitted from the argument,
				       six digits are output; if the precision
				       is explicitly 0,	no radix appears.

			       The floating-point-number argument  is  printed
			       in the style
				       ,  where	 there is one digit before the
				       radix character,	and the	number of dig-
				       its after it is equal to	the precision.
				       When the	precision is missing, six dig-
				       its  are	 produced; if the precision is
				       0, no  radix  character	appears.   The
				       conversion  character produces a	number
				       with introducing	the  exponent  instead
				       of  The	exponent  always  contains  at
				       least  two  digits.   However,  if  the
				       value  to  be printed requires an expo-
				       nent greater  than  two	digits,	 addi-
				       tional  exponent	 digits	are printed as
				       necessary.

			       The floating-point-number argument  is  printed
			       in style
				       or  (or int style in the	case of	a con-
				       version character), with	the  precision
				       specifying  the	number	of significant
				       digits.	The style used depends on  the
				       value  converted; style is used only if
				       the exponent resulting from the conver-
				       sion  is	 less  than or greater than or
				       equal to	the precision.	Trailing zeros
				       are  remove  from  the result.  A radix
				       character appears only if  it  is  fol-
				       lowed by	a digit.

			       The first character of the argument is printed.

			       The argument is taken to	be a string,
				       and  characters	from  the  string  are
				       printed until the end of	the string  or
				       the  number  of characters indicated by
				       the precision specification of the  ar-
				       gument is reached.  If the precision is
				       omitted from the	argument, it is	inter-
				       preted  as  infinite and	all characters
				       up  to  the  end	 of  the  string   are
				       printed.

			       Print a character; no argument is converted.

			       Similar to the
				       conversion  specifier,  except that the
				       string can contain backslash-escape se-
				       quences which are then converted	to the
				       characters they represent.  will	 cause
				       to  ignore  any remaining characters in
				       the string operand containing  it,  any
				       remaining string	operands and any addi-
				       tional characters in the	 format	 oper-
				       and.

			  In  no case does a nonexistent or insufficient field
			  width	cause truncation of a field; if	the result  of
			  a  conversion	 is  wider  than  the field width, the
			  field	is simply expanded to contain  the  conversion
			  result.

EXTERNAL INFLUENCES
   Environment Variables
       determines  the interpretation of arg as	single and/or multi-byte char-
       acters.

       determines the language in which	messages are displayed.

       If or is	not specified in the  environment  or  is  set	to  the	 empty
       string, the value of is used as a default for each unspecified or empty
       variable.  If is	not specified or is set	to the empty string, a default
       of "C" (see lang(5)) is used instead of

       If  any	internationalization  variable	contains  an  invalid setting,
       printf behaves as if all	internationalization variables are set to "C".
       See environ(5).

   International Code Set Support
       Single- and multi-byte character	code sets are supported.

RETURN VALUE
       exits with one of the following values:

	       0     Successful	completion;

	      >0     Errors  occurred.	The exit value is increased by one for
		     each error	that occurred up to a maximum of 255.

DIAGNOSTICS
       If an argument cannot be	converted into a form suitable for the	corre-
       sponding	 conversion  specification,  or	for any	other reason cannot be
       correctly printed, a diagnostic message is printed to  standard	error,
       the  argument is	output as a string form	as it was given	on the command
       line, and the exit value	is incremented.

EXAMPLES
       The following command prints the	number 123 in octal,  hexadecimal  and
       floating	point formats in their alternate form

	      printf "%#o, %#x,	%#X, %#f, %#g, %#e\n" 123 123 123 123 123 123

       resulting in the	following output

       Print the outputs with their corresponding field	widths and precision:

	      printf "%.6d, %10.6d, %.6f, %.6e,	%.6s\n"	123 123	1.23 123.4 MoreThanSix

       resulting in the	following output

SEE ALSO
       echo(1),	printf(3S).

STANDARDS CONFORMANCE
								     printf(1)

NAME | SYNOPSIS | DESCRIPTION | EXTERNAL INFLUENCES | RETURN VALUE | DIAGNOSTICS | EXAMPLES | SEE ALSO | STANDARDS CONFORMANCE

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=printf&sektion=1&manpath=HP-UX+11.22>

home | help