📄 fold.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-2003 The Open Group, All Rights Reserved --><title>fold</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="fold"></a> <a name="tag_04_56"></a><!-- fold --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_04_56_01"></a>NAME</h4><blockquote>fold - filter for folding lines</blockquote><h4><a name="tag_04_56_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>fold</tt> <b>[</b><tt>-bs</tt><b>][</b><tt>-w</tt> <i>width</i><b>][</b><i>file</i><tt>...</tt><b>]</b></code></p></blockquote><h4><a name="tag_04_56_03"></a>DESCRIPTION</h4><blockquote><p>The <i>fold</i> utility is a filter that shall fold lines from its input files, breaking the lines to have a maximum of<i>width</i> column positions (or bytes, if the <b>-b</b> option is specified). Lines shall be broken by the insertion of a<newline> such that each output line (referred to later in this section as a <i>segment</i>) is the maximum width possiblethat does not exceed the specified number of column positions (or bytes). A line shall not be broken in the middle of a character.The behavior is undefined if <i>width</i> is less than the number of columns any single character in the input would occupy.</p><p>If the <carriage-return>s, <backspace>s, or <tab>s are encountered in the input, and the <b>-b</b> option isnot specified, they shall be treated specially:</p><dl compact><dt><backspace></dt><dd>The current count of line width shall be decremented by one, although the count never shall become negative. The <i>fold</i>utility shall not insert a <newline> immediately before or after any <backspace>.</dd><dt><carriage-return></dt><dd><br>The current count of line width shall be set to zero. The <i>fold</i> utility shall not insert a <newline> immediately beforeor after any <carriage-return>.</dd><dt><tab></dt><dd>Each <tab> encountered shall advance the column position pointer to the next tab stop. Tab stops shall be at each columnposition <i>n</i> such that <i>n</i> modulo 8 equals 1.</dd></dl></blockquote><h4><a name="tag_04_56_04"></a>OPTIONS</h4><blockquote><p>The <i>fold</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 options shall be supported:</p><dl compact><dt><b>-b</b></dt><dd>Count <i>width</i> in bytes rather than column positions.</dd><dt><b>-s</b></dt><dd>If a segment of a line contains a <blank> within the first <i>width</i> column positions (or bytes), break the line afterthe last such <blank> meeting the width constraints. If there is no <blank> meeting the requirements, the <b>-s</b>option shall have no effect for that output segment of the input line.</dd><dt><b>-w </b> <i>width</i></dt><dd>Specify the maximum line length, in column positions (or bytes if <b>-b</b> is specified). The results are unspecified if<i>width</i> is not a positive decimal number. The default value shall be 80.</dd></dl></blockquote><h4><a name="tag_04_56_05"></a>OPERANDS</h4><blockquote><p>The following operand shall be supported:</p><dl compact><dt><i>file</i></dt><dd>A pathname of a text file to be folded. If no <i>file</i> operands are specified, the standard input shall be used.</dd></dl></blockquote><h4><a name="tag_04_56_06"></a>STDIN</h4><blockquote><p>The standard input shall be used only if no <i>file</i> operands are specified. See the INPUT FILES section.</p></blockquote><h4><a name="tag_04_56_07"></a>INPUT FILES</h4><blockquote><p>If the <b>-b</b> option is specified, the input files shall be text files except that the lines are not limited to {LINE_MAX}bytes in length. If the <b>-b</b> option is not specified, the input files shall be text files.</p></blockquote><h4><a name="tag_04_56_08"></a>ENVIRONMENT VARIABLES</h4><blockquote><p>The following environment variables shall affect the execution of <i>fold</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 ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> forthe 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 asopposed to multi-byte characters in arguments and input files), and for the determination of the width in column positions eachcharacter would occupy on a constant-width font output device.</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 standarderror.</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_56_09"></a>ASYNCHRONOUS EVENTS</h4><blockquote><p>Default.</p></blockquote><h4><a name="tag_04_56_10"></a>STDOUT</h4><blockquote><p>The standard output shall be a file containing a sequence of characters whose order shall be preserved from the input files,possibly with inserted <newline>s.</p></blockquote><h4><a name="tag_04_56_11"></a>STDERR</h4><blockquote><p>The standard error shall be used only for diagnostic messages.</p></blockquote><h4><a name="tag_04_56_12"></a>OUTPUT FILES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_56_13"></a>EXTENDED DESCRIPTION</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_56_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 processed successfully.</dd><dt>>0</dt><dd>An error occurred.</dd></dl></blockquote><h4><a name="tag_04_56_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_56_16"></a>APPLICATION USAGE</h4><blockquote><p>The <a href="../utilities/cut.html"><i>cut</i></a> and <i>fold</i> utilities can be used to create text files out of files witharbitrary line lengths. The <a href="../utilities/cut.html"><i>cut</i></a> utility should be used when the number of lines (orrecords) needs to remain constant. The <i>fold</i> utility should be used when the contents of long lines need to be keptcontiguous.</p><p>The <i>fold</i> utility is frequently used to send text files to printers that truncate, rather than fold, lines wider than theprinter is able to print (usually 80 or 132 column positions).</p></blockquote><h4><a name="tag_04_56_17"></a>EXAMPLES</h4><blockquote><p>An example invocation that submits a file of possibly long lines to the printer (under the assumption that the user knows theline width of the printer to be assigned by <a href="../utilities/lp.html"><i>lp</i></a>):</p><pre><tt>fold -w 132 bigfile | lp</tt></pre></blockquote><h4><a name="tag_04_56_18"></a>RATIONALE</h4><blockquote><p>Although terminal input in canonical processing mode requires the erase character (frequently set to <backspace>) to erasethe previous character (not byte or column position), terminal output is not buffered and is extremely difficult, if notimpossible, to parse correctly; the interpretation depends entirely on the physical device that actually displays/prints/stores theoutput. In all known internationalized implementations, the utilities producing output for mixed column-width output assume that a<backspace> backs up one column position and outputs enough <backspace>s to return to the start of the character when<backspace> is used to provide local line motions to support underlining and emboldening operations. Since <i>fold</i>without the <b>-b</b> option is dealing with these same constraints, <backspace> is always treated as backing up one columnposition rather than backing up one character.</p><p>Historical versions of the <i>fold</i> utility assumed 1 byte was one character and occupied one column position when writtenout. This is no longer always true. Since the most common usage of <i>fold</i> is believed to be folding long lines for output tolimited-length output devices, this capability was preserved as the default case. The <b>-b</b> option was added so thatapplications could <i>fold</i> files with arbitrary length lines into text files that could then be processed by the standardutilities. Note that although the width for the <b>-b</b> option is in bytes, a line is never split in the middle of a character.(It is unspecified what happens if a width is specified that is too small to hold a single character found in the input followed bya <newline>.)</p><p>The tab stops are hardcoded to be every eighth column to meet historical practice. No new method of specifying other tab stopswas invented.</p></blockquote><h4><a name="tag_04_56_19"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_56_20"></a>SEE ALSO</h4><blockquote><p><a href="cut.html"><i>cut</i></a></p></blockquote><h4><a name="tag_04_56_21"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 4.</p></blockquote><h4><a name="tag_04_56_22"></a>Issue 6</h4><blockquote><p>The normative text is reworded to avoid use of the term "must" for application requirements.</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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -