printf man page on HP-UX

Printed from http://www.polarhome.com/service/man/?qf=printf&af=0&tf=2&of=HP-UX

printf(1)							     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 (see printf(3S)), and contains the following 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 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
					 effect.  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  bytes  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 bytes to be
			  printed  from	 a string in s conversion.  The preci‐
			  sion takes the form of a period followed by a	 deci‐
			  mal 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
			       inte‐
			       ger
			       argu‐
			       ment
			       is
			       printed
			       a
			       signed
			       dec‐
			       i‐
			       mal     or
				       unsigned
				       octal
				       unsigned
				       dec‐
				       i‐
				       mal
				       or
				       unsigned
				       hexa‐
				       dec‐
				       i‐
				       mal
				       nota‐
				       tion
				       and
				       The
				       con‐
				       ver‐
				       sion
				       uses
				       the
				       num‐
				       bers
				       and
				       let‐
				       ters
				       and
				       the
				       con‐
				       ver‐
				       sion
				       uses
				       the
				       num‐
				       bers
				       and
				       let‐
				       ters
				       The
				       pre‐
				       ci‐
				       sion
				       com‐
				       po‐
				       nent
				       of
				       the
				       argu‐
				       ment
				       spec‐
				       i‐
				       fies
				       the
				       min‐
				       i‐
				       mum
				       num‐
				       ber
				       of
				       dig‐
				       its
				       to
				       appear.
				       If
				       the
				       value
				       being
				       con‐
				       verted
				       can
				       be
				       rep‐
				       re‐
				       sented
				       in
				       fewer
				       dig‐
				       its
				       than
				       the
				       spec‐
				       i‐
				       fied
				       min‐
				       i‐
				       mum,
				       it
				       is
				       expanded
				       with
				       lead‐
				       ing
				       zeroes.
				       The
				       default
				       pre‐
				       ci‐
				       sion
				       is
				       1.
				       The
				       result
				       of
				       con‐
				       vert‐
				       ing
				       a
				       zero
				       value
				       with
				       a
				       pre‐
				       ci‐
				       sion
				       of
				       0
				       is
				       no
				       char‐
				       ac‐
				       ters.

			       The
			       float‐
			       ing-
			       point
			       num‐
			       ber
			       argu‐
			       ment    is
				       printed
				       in
				       dec‐
				       i‐
				       mal
				       nota‐
				       tion
				       in
				       the
				       style
				       ,
				       where
				       the
				       num‐
				       ber
				       of
				       dig‐
				       its
				       after
				       the
				       radix
				       char‐
				       ac‐
				       ter,
				       is
				       equal
				       to
				       the
				       pre‐
				       ci‐
				       sion
				       spec‐
				       i‐
				       fi‐
				       ca‐
				       tion.
				       If
				       the
				       pre‐
				       ci‐
				       sion
				       is
				       omit‐
				       ted
				       from
				       the
				       argu‐
				       ment,
				       six
				       dig‐
				       its
				       are
				       out‐
				       put;
				       if
				       the
				       pre‐
				       ci‐
				       sion
				       is
				       explic‐
				       itly
				       0,
				       no
				       radix
				       appears.

			       The
			       float‐
			       ing-
			       point-
			       num‐
			       ber
			       argu‐
			       ment
			       is
			       printed
			       in
			       the
			       style   ,
				       where
				       there
				       is
				       one
				       digit
				       before
				       the
				       radix
				       char‐
				       ac‐
				       ter,
				       and
				       the
				       num‐
				       ber
				       of
				       dig‐
				       its
				       after
				       it
				       is
				       equal
				       to
				       the
				       pre‐
				       ci‐
				       sion.
				       When
				       the
				       pre‐
				       ci‐
				       sion
				       is
				       miss‐
				       ing,
				       six
				       dig‐
				       its
				       are
				       pro‐
				       duced;
				       if
				       the
				       pre‐
				       ci‐
				       sion
				       is
				       0,
				       no
				       radix
				       char‐
				       ac‐
				       ter
				       appears.
				       The
				       con‐
				       ver‐
				       sion
				       char‐
				       ac‐
				       ter
				       pro‐
				       duces
				       a
				       num‐
				       ber
				       with
				       intro‐
				       duc‐
				       ing
				       the
				       expo‐
				       nent
				       instead
				       of
				       The
				       expo‐
				       nent
				       always
				       con‐
				       tains
				       at
				       least
				       two
				       dig‐
				       its.
				       How‐
				       ever,
				       if
				       the
				       value
				       to
				       be
				       printed
				       requires
				       an
				       expo‐
				       nent
				       greater
				       than
				       two
				       dig‐
				       its,
				       addi‐
				       tional
				       expo‐
				       nent
				       dig‐
				       its
				       are
				       printed
				       as
				       nec‐
				       es‐
				       sary.

			       The
			       float‐
			       ing-
			       point-
			       num‐
			       ber
			       argu‐
			       ment
			       is
			       printed
			       in
			       style   or
				       (or
				       int
				       style
				       in
				       the
				       case
				       of
				       a
				       con‐
				       ver‐
				       sion
				       char‐
				       ac‐
				       ter),
				       with
				       the
				       pre‐
				       ci‐
				       sion
				       spec‐
				       i‐
				       fy‐
				       ing
				       the
				       num‐
				       ber
				       of
				       sig‐
				       nif‐
				       i‐
				       cant
				       dig‐
				       its.
				       The
				       style
				       used
				       depends
				       on
				       the
				       value
				       con‐
				       verted;
				       style
				       is
				       used
				       only
				       if
				       the
				       expo‐
				       nent
				       result‐
				       ing
				       from
				       the
				       con‐
				       ver‐
				       sion
				       is
				       less
				       than
				       or
				       greater
				       than
				       or
				       equal
				       to
				       the
				       pre‐
				       ci‐
				       sion.
				       Trail‐
				       ing
				       zeros
				       are
				       remove
				       from
				       the
				       result.
				       A
				       radix
				       char‐
				       ac‐
				       ter
				       appears
				       only
				       if
				       it
				       is
				       fol‐
				       lowed
				       by
				       a
				       digit.

			       The
			       first
			       byte
			       of
			       the
			       argu‐
			       ment
			       is
			       printed.

			       The
			       argu‐
			       ment
			       is
			       taken
			       to
			       be
			       a
			       string, and
				       char‐
				       ac‐
				       ters
				       from
				       the
				       string
				       are
				       printed
				       until
				       the
				       end
				       of
				       the
				       string
				       or
				       the
				       num‐
				       ber
				       of
				       bytes
				       indi‐
				       cated
				       by
				       the
				       pre‐
				       ci‐
				       sion
				       spec‐
				       i‐
				       fi‐
				       ca‐
				       tion
				       of
				       the
				       argu‐
				       ment
				       is
				       reached.
				       If
				       the
				       pre‐
				       ci‐
				       sion
				       is
				       omit‐
				       ted
				       from
				       the
				       argu‐
				       ment,
				       it
				       is
				       inter‐
				       preted
				       as
				       infi‐
				       nite
				       and
				       all
				       char‐
				       ac‐
				       ters
				       up
				       to
				       the
				       end
				       of
				       the
				       string
				       are
				       printed.

			       Print
			       a       char‐
				       ac‐
				       ter;
				       no
				       argu‐
				       ment
				       is
				       con‐
				       verted.

			       Sim‐
			       i‐
			       lar
			       to
			       the     con‐
				       ver‐
				       sion
				       spec‐
				       i‐
				       fier,
				       except
				       that
				       the
				       string
				       can
				       con‐
				       tain
				       back‐
				       slash-
				       escape
				       sequences
				       which
				       are
				       then
				       con‐
				       verted
				       to
				       the
				       char‐
				       ac‐
				       ters
				       they
				       rep‐
				       re‐
				       sent.
				       will
				       cause
				       to
				       ignore
				       any
				       remain‐
				       ing
				       char‐
				       ac‐
				       ters
				       in
				       the
				       string
				       op‐
				       er‐
				       and
				       con‐
				       tain‐
				       ing
				       it,
				       any
				       remain‐
				       ing
				       string
				       op‐
				       er‐
				       ands
				       and
				       any
				       addi‐
				       tional
				       char‐
				       ac‐
				       ters
				       in
				       the
				       for‐
				       mat
				       op‐
				       er‐
				       and.

			  In
			  no
			  case
			  does
			  a
			  nonex‐
			  is‐
			  tent
			  or
			  insuf‐
			  fi‐
			  cient
			  field
			  width
			  cause
			  trun‐
			  ca‐
			  tion
			  of
			  a
			  field;
			  if
			  the
			  result
			  of
			  a
			  con‐
			  ver‐
			  sion
			  is
			  wider
			  than
			  the
			  field
			  width,
			  the
			  field
			  is
			  sim‐
			  ply
			  expanded
			  to
			  con‐
			  tain
			  the
			  con‐
			  ver‐
			  sion
			  result.

EXTERNAL  INFLU‐
       ENCES
   Environment
       Variables
       deter‐
       mines the
       interpre‐
       tation of
       arg    as
       single
       and/or
       multi-
       byte
       charac‐
       ters.

       deter‐
       mines the
       language
       in  which
       messages
       are  dis‐
       played.

       If or  is
       not spec‐
       ified  in
       the envi‐
       ronment
       or is set
       to    the
       empty
       string,
       the value
       of     is
       used as a
       default
       for  each
       unspeci‐
       fied   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
       interna‐
       tional‐
       ization
       variable
       contains
       an
       invalid
       setting,
       printf
       behaves
       as if all
       interna‐
       tional‐
       ization
       variables
       are   set
       to   "C".
       See envi‐
       ron(5).

   International
       Code  Set
       Support
       Single
       and
       multi-
       byte
       character
       code sets
       are  sup‐
       ported.

RETURN VALUE
       exits
       with  one
       of    the
       following
       values:

	      Suc‐
	      cess‐
	      ful
	      com‐
	      ple‐
	      tion.

	      Errors
	      occurred;
	      the
	      exit
	      value
	      is
	      increased
	      by
	      one
	      for
	      each
	      error
	      that
		     occurred
		     up
		     to
		     a
		     max‐
		     i‐
		     mum
		     of
		     255.

DIAGNOSTICS
       If     an
       argument
       cannot be
       converted
       into    a
       form
       suitable
       for   the
       corre‐
       sponding
       conver‐
       sion
       specifi‐
       cation,
       or    for
       any other
       reason
       cannot be
       correctly
       printed,
       a   diag‐
       nostic
       message
       is
       printed
       to  stan‐
       dard
       error,
       the argu‐
       ment   is
       output as
       a  string
       form   as
       it    was
       given  on
       the  com‐
       mand
       line, and
       the  exit
       value  is
       incre‐
       mented.

EXAMPLES
       The  fol‐
       lowing
       command
       prints
       the  num‐
       ber   123
       in octal,
       hexadeci‐
       mal   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
       corre‐
       sponding
       field
       widths
       and  pre‐
       cision:

	      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   CON‐
       FORMANCE
								     printf(1)
[top]

List of man pages available for HP-UX

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net