Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

printf(3S)



PRINTF(1)           RISC/os Reference Manual            PRINTF(1)



NAME
     printf - print formatted output

SYNOPSIS
     printf format [arg ...]

DESCRIPTION
     The printf command converts, formats, and prints its args
     under control of the format.  It fully supports conversion
     specifications for strings (%s descriptor); however, the
     results are undefined for the other conversion specifica-
     tions supported by printf(3S).

     format    a character string that contains three types of
               objects:  1) plain characters, which are simply
               copied to the output stream; 2) conversion specif-
               ications, each of which results in fetching zero
               or more args; and 3) C-language escape sequences,
               which are translated into the corresponding char-
               acters.

     arg       string(s) to be printed under the control of for-
               mat.  The results are undefined if there are
               insufficient args for the format.  If the format
               is exhausted while args remain, the excess args
               are simply ignored.

     Each conversion specification is introduced by the character
     %.  After the %, the following appear in sequence:

          An optional field, consisting of a decimal digit string
          followed by a $, specifying the next arg to be con-
          verted.  If this field is not provided, the arg follow-
          ing the last arg converted is used.

          An optional decimal digit string specifying a minimum
          field width.  If the converted value has fewer charac-
          ters than the field width, it is padded on the left (or
          right, if the left-adjustment flag `-' has been given)
          to the field width.  The padding is with blanks unless
          the field width digit string starts with a zero, in
          which case the padding is with zeros.

          An optional precision that gives the maximum number of
          characters to be printed from a string in %s conver-
          sion.  The precision takes the form of a period (.)
          followed by a decimal digit string; a null digit string
          is treated as zero (nothing is printed).  Padding
          specified by the precision overrides the padding speci-
          fied by the field width.  That is, if precision is
          specified, its value is used to control the number of
          characters printed.



                        Printed 11/19/92                   Page 1





PRINTF(1)           RISC/os Reference Manual            PRINTF(1)



          A field width or precision or both may be indicated by
          an asterisk (*) instead of a digit string.  In this
          case, an integer arg supplies the field width or preci-
          sion.  The arg that is actually converted is not
          fetched until the conversion letter is seen, so the
          args specifying field width or precision must appear
          before the arg (if any) to be converted.  A negative
          field width argument is taken as a `-' (left-
          adjustment) flag followed by a positive field width. If
          the precision argument is negative, it is changed to
          zero (nothing is printed).  In no case does a non-
          existent or small 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.

     The conversion characters and their meanings are:

     %s   The arg is taken to be a string and characters from the
          string are printed until a null character (\0) is
          encountered or the number of characters indicated by
          the precision specification is reached.  If the preci-
          sion is missing, it is taken to be infinite, so all
          characters up to the first null character are printed.
          A null value for arg yields undefined results.

     %%   Print a %; no argument is converted.

EXAMPLES
     The command

          printf '%s %s %s\n' Good Morning World

     results in the output:

          Good Morning World

     The following command produces the same output.

          printf '%2$s %s %1$s\n' World Good Morning

     Here is an example that prints the first 6 characters of
     $PATH left-adjusted in a 10-character field:

          printf 'First 6 chars of %s are %-10.6s.\n' $PATH $PATH

     If $PATH has the value /usr/bin:/usr/local/bin, then the
     above command would print the following output:

          First 6 chars of /usr/bin:/usr/local/bin are /usr/b .





 Page 2                 Printed 11/19/92





PRINTF(1)           RISC/os Reference Manual            PRINTF(1)



SEE ALSO
     printf(3S) in the Programmer's Reference Manual.





















































                        Printed 11/19/92                   Page 3



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026