325 lines
9.9 KiB
HTML
325 lines
9.9 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>cat</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="cat"></a> <a name="tag_04_14"></a><!-- cat -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_04_14_01"></a>NAME</h4>
|
|
|
|
<blockquote>cat - concatenate and print files</blockquote>
|
|
|
|
<h4><a name="tag_04_14_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>cat</tt> <b>[</b><tt>-u</tt><b>][</b><i>file</i> <tt>...</tt><b>]</b></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>cat</i> utility shall read files in sequence and shall write their contents to the standard output in the same
|
|
sequence.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_04"></a>OPTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>cat</i> utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, <a href=
|
|
"../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p>
|
|
|
|
<p>The following option shall be supported:</p>
|
|
|
|
<dl compact>
|
|
<dt><b>-u</b></dt>
|
|
|
|
<dd>Write bytes from the input file to the standard output without delay as each is read.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_05"></a>OPERANDS</h4>
|
|
|
|
<blockquote>
|
|
<p>The following operand shall be supported:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>file</i></dt>
|
|
|
|
<dd>A pathname of an input file. If no <i>file</i> operands are specified, the standard input shall be used. If a <i>file</i> is
|
|
<tt>'-'</tt> , the <i>cat</i> utility shall read from the standard input at that point in the sequence. The <i>cat</i> utility
|
|
shall not close and reopen standard input when it is referenced in this way, but shall accept multiple occurrences of <tt>'-'</tt>
|
|
as a <i>file</i> operand.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_06"></a>STDIN</h4>
|
|
|
|
<blockquote>
|
|
<p>The standard input shall be used only if no <i>file</i> operands are specified, or if a <i>file</i> operand is <tt>'-'</tt> .
|
|
See the INPUT FILES section.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_07"></a>INPUT FILES</h4>
|
|
|
|
<blockquote>
|
|
<p>The input files can be any file type.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_08"></a>ENVIRONMENT VARIABLES</h4>
|
|
|
|
<blockquote>
|
|
<p>The following environment variables shall affect the execution of <i>cat</i>:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>LANG</i></dt>
|
|
|
|
<dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> for
|
|
the precedence of internationalization variables used to determine the values of locale categories.)</dd>
|
|
|
|
<dt><i>LC_ALL</i></dt>
|
|
|
|
<dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
|
|
|
|
<dt><i>LC_CTYPE</i></dt>
|
|
|
|
<dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
|
|
opposed to multi-byte characters in arguments).</dd>
|
|
|
|
<dt><i>LC_MESSAGES</i></dt>
|
|
|
|
<dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard
|
|
error.</dd>
|
|
|
|
<dt><i>NLSPATH</i></dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt=
|
|
"[Option End]" border="0"></dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_09"></a>ASYNCHRONOUS EVENTS</h4>
|
|
|
|
<blockquote>
|
|
<p>Default.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_10"></a>STDOUT</h4>
|
|
|
|
<blockquote>
|
|
<p>The standard output shall contain the sequence of bytes read from the input files. Nothing else shall be written to the standard
|
|
output.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_11"></a>STDERR</h4>
|
|
|
|
<blockquote>
|
|
<p>The standard error shall be used only for diagnostic messages.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_12"></a>OUTPUT FILES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_13"></a>EXTENDED DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_14"></a>EXIT STATUS</h4>
|
|
|
|
<blockquote>
|
|
<p>The following exit values shall be returned:</p>
|
|
|
|
<dl compact>
|
|
<dt> 0</dt>
|
|
|
|
<dd>All input files were output successfully.</dd>
|
|
|
|
<dt>>0</dt>
|
|
|
|
<dd>An error occurred.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_15"></a>CONSEQUENCES OF ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>Default.</p>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_04_14_16"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>The <b>-u</b> option has value in prototyping non-blocking reads from FIFOs. The intent is to support the following
|
|
sequence:</p>
|
|
|
|
<pre>
|
|
<tt>mkfifo foo
|
|
cat -u foo > /dev/tty13 &
|
|
cat -u > foo
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>It is unspecified whether standard output is or is not buffered in the default case. This is sometimes of interest when standard
|
|
output is associated with a terminal, since buffering may delay the output. The presence of the <b>-u</b> option guarantees that
|
|
unbuffered I/O is available. It is implementation-defined whether the <i>cat</i> utility buffers output if the <b>-u</b> option is
|
|
not specified. Traditionally, the <b>-u</b> option is implemented using the equivalent of the <a href=
|
|
"../functions/setvbuf.html"><i>setvbuf</i>()</a> function defined in the System Interfaces volume of
|
|
IEEE Std 1003.1-2001.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_17"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>The following command:</p>
|
|
|
|
<pre>
|
|
<tt>cat myfile
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>writes the contents of the file <b>myfile</b> to standard output.</p>
|
|
|
|
<p>The following command:</p>
|
|
|
|
<pre>
|
|
<tt>cat doc1 doc2 > doc.all
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>concatenates the files <b>doc1</b> and <b>doc2</b> and writes the result to <b>doc.all</b>.</p>
|
|
|
|
<p>Because of the shell language mechanism used to perform output redirection, a command such as this:</p>
|
|
|
|
<pre>
|
|
<tt>cat doc doc.end > doc
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>causes the original data in <b>doc</b> to be lost.</p>
|
|
|
|
<p>The command:</p>
|
|
|
|
<pre>
|
|
<tt>cat start - middle - end > file
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>when standard input is a terminal, gets two arbitrary pieces of input from the terminal with a single invocation of <i>cat</i>.
|
|
Note, however, that if standard input is a regular file, this would be equivalent to the command:</p>
|
|
|
|
<pre>
|
|
<tt>cat start - middle /dev/null end > file
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>because the entire contents of the file would be consumed by <i>cat</i> the first time <tt>'-'</tt> was used as a <i>file</i>
|
|
operand and an end-of-file condition would be detected immediately when <tt>'-'</tt> was referenced the second time.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_18"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>Historical versions of the <i>cat</i> utility include the options <b>-e</b>, <b>-t</b>, and <b>-v</b>, which permit the ends of
|
|
lines, <tab>s, and invisible characters, respectively, to be rendered visible in the output. The standard developers omitted
|
|
these options because they provide too fine a degree of control over what is made visible, and similar output can be obtained using
|
|
a command such as:</p>
|
|
|
|
<pre>
|
|
<tt>sed -n -e 's/$/$/' -e l pathname
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>The <b>-s</b> option was omitted because it corresponds to different functions in BSD and System V-based systems. The BSD
|
|
<b>-s</b> option to squeeze blank lines can be accomplished by the shell script shown in the following example:</p>
|
|
|
|
<pre>
|
|
<tt>sed -n '
|
|
# Write non-empty lines.
|
|
/./ {
|
|
p
|
|
d
|
|
}
|
|
# Write a single empty line, then look for more empty lines.
|
|
/^$/ p
|
|
# Get next line, discard the held <newline> (empty line),
|
|
# and look for more empty lines.
|
|
:Empty
|
|
/^$/ {
|
|
N
|
|
s/.//
|
|
b Empty
|
|
}
|
|
# Write the non-empty line before going back to search
|
|
# for the first in a set of empty lines.
|
|
p
|
|
'
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>The System V <b>-s</b> option to silence error messages can be accomplished by redirecting the standard error. Note that the BSD
|
|
documentation for <i>cat</i> uses the term "blank line" to mean the same as the POSIX "empty line'': a line consisting only of a
|
|
<newline>.</p>
|
|
|
|
<p>The BSD <b>-n</b> option was omitted because similar functionality can be obtained from the <b>-n</b> option of the <a href=
|
|
"../utilities/pr.html"><i>pr</i></a> utility.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_19"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_20"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="more.html"><i>more</i></a> , the System Interfaces volume of IEEE Std 1003.1-2001, <a href=
|
|
"../functions/setvbuf.html"><i>setvbuf</i>()</a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_14_21"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 2.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|