Unix™ Systems Programming [Electronic resources] : Communication, Concurrency, and Threads نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Unix™ Systems Programming [Electronic resources] : Communication, Concurrency, and Threads - نسخه متنی

Prentice Hall

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید










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.



    / 276