Utility

Team-FLY

4.10 Exercise: A cat Utility

The cat utility has the following POSIX specification[52].

 NAME cat - concatenate and print files SYNOPSIS cat [-u] [file ...] DESCRIPTION         The cat utility shall read files in sequence and shall write         their contents to the standard output in the same sequence. OPTIONS         The cat utility shall conform to the Base Definitions volume         of IEEE STd 1003.1-2001, Section 12.2, Utility Syntax Guidelines.         The following option shall be supported:         -u      Write bytes from the input file to the standard output                 without delay as each is read OPERANDS         The following operand shall be supported:         file    A pathname of an input file. If no file operands are                 specified, the standard input shall be used. If a file                 is '-', the cat utility shall read from the standard                 input at that point in the sequence. The cat utility                 shall not close and reopen standard input when it is                 referenced in this way, but shall accept multiple                 occurrences of '-' as a file operand. STDIN         The standard input shall be used only if no file operands are         specified, or if a file operand is '-'. See the INPUT FILES         section. INPUT FILES         The input files can be any file type. ENVIRONMENT VARIABLES         (.... a long section omitted here ....) ASYNCHRONOUS EVENTS         Default. STDOUT         The standard output shall contain the sequence of bytes read from         the input files.  Nothing else shall be written to the standard         output. STDERR         The standard error shall be used only for diagnostic messages. OUTPUT FILES         None. EXTENDED DESCRIPTION         None. EXIT STATUS         The following exit values shall be returned:         0:      All input files were output successfully.         >0      An error occurred. CONSEQUENCES OF ERRORS         Default. 

The actual POSIX description continues with other sections, including APPLICATION USAGE , EXAMPLES and RATIONALE .

  1. Compare the POSIX description of cat with the man page for cat on your system and note any differences.

  2. Execute the cat command for many examples, including multiple input files and files that don't exist. Include a case in which you redirect standard input to a disk file and use several '-' files on the command line. Explain what happens.

  3. Write your own cat utility to conform to the standard. Try to duplicate the behavior of the actual cat utility.

  4. Read the section of the cat man page on ENVIRONMENT VARIABLES .

  5. Experiment with the effect of relevant environment variables on the behavior of cat .

  6. Incorporate the handling of environment variables into your own cat utility.

Team-FLY


Unix Systems Programming
UNIX Systems Programming: Communication, Concurrency and Threads
ISBN: 0130424110
EAN: 2147483647
Year: 2003
Pages: 274

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net