logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

fold.1p (8936B)


  1. '\" et
  2. .TH FOLD "1P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. fold
  12. \(em filter for folding lines
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. fold \fB[\fR-bs\fB] [\fR-w \fIwidth\fB] [\fIfile\fR...\fB]\fR
  17. .fi
  18. .SH DESCRIPTION
  19. The
  20. .IR fold
  21. utility is a filter that shall fold lines from its input files,
  22. breaking the lines to have a maximum of
  23. .IR width
  24. column positions (or bytes, if the
  25. .BR \-b
  26. option is specified). Lines shall be broken by the insertion of a
  27. <newline>
  28. such that each output line (referred to later in this section
  29. as a \fIsegment\fP) is the maximum width possible that does not exceed
  30. the specified number of column positions (or bytes). A line shall not
  31. be broken in the middle of a character. The behavior is undefined if
  32. .IR width
  33. is less than the number of columns any single character in the input
  34. would occupy.
  35. .P
  36. If the
  37. <carriage-return>,
  38. <backspace>,
  39. or
  40. <tab>
  41. characters are encountered in the input, and the
  42. .BR \-b
  43. option is not specified, they shall be treated specially:
  44. .IP <backspace> 10
  45. The current count of line width shall be decremented by one, although
  46. the count never shall become negative. The
  47. .IR fold
  48. utility shall not insert a
  49. <newline>
  50. immediately before or after any
  51. <backspace>,
  52. unless the following character has a width greater than 1 and would
  53. cause the line width to exceed
  54. .IR width .
  55. .IP <carriage-return> 10
  56. .br
  57. The current count of line width shall be set to zero. The
  58. .IR fold
  59. utility shall not insert a
  60. <newline>
  61. immediately before or after any
  62. <carriage-return>.
  63. .IP <tab> 10
  64. Each
  65. <tab>
  66. encountered shall advance the column position pointer to the next tab
  67. stop. Tab stops shall be at each column position
  68. .IR n
  69. such that
  70. .IR n
  71. modulo 8 equals 1.
  72. .SH OPTIONS
  73. The
  74. .IR fold
  75. utility shall conform to the Base Definitions volume of POSIX.1\(hy2017,
  76. .IR "Section 12.2" ", " "Utility Syntax Guidelines".
  77. .P
  78. The following options shall be supported:
  79. .IP "\fB\-b\fR" 10
  80. Count
  81. .IR width
  82. in bytes rather than column positions.
  83. .IP "\fB\-s\fR" 10
  84. If a segment of a line contains a
  85. <blank>
  86. within the first
  87. .IR width
  88. column positions (or bytes), break the line after the last such
  89. <blank>
  90. meeting the width constraints. If there is no
  91. <blank>
  92. meeting the requirements, the
  93. .BR \-s
  94. option shall have no effect for that output segment of the input line.
  95. .IP "\fB\-w\ \fIwidth\fR" 10
  96. Specify the maximum line length, in column positions (or bytes if
  97. .BR \-b
  98. is specified). The results are unspecified if
  99. .IR width
  100. is not a positive decimal number. The default value shall be 80.
  101. .SH OPERANDS
  102. The following operand shall be supported:
  103. .IP "\fIfile\fR" 10
  104. A pathname of a text file to be folded. If no
  105. .IR file
  106. operands are specified, the standard input shall be used.
  107. .SH STDIN
  108. The standard input shall be used if no
  109. .IR file
  110. operands are specified, and shall be used if a
  111. .IR file
  112. operand is
  113. .BR '\-'
  114. and the implementation treats the
  115. .BR '\-'
  116. as meaning standard input.
  117. Otherwise, the standard input shall not be used.
  118. See the INPUT FILES section.
  119. .SH "INPUT FILES"
  120. If the
  121. .BR \-b
  122. option is specified, the input files shall be text files except that the
  123. lines are not limited to
  124. {LINE_MAX}
  125. bytes in length. If the
  126. .BR \-b
  127. option is not specified, the input files shall be text files.
  128. .SH "ENVIRONMENT VARIABLES"
  129. The following environment variables shall affect the execution of
  130. .IR fold :
  131. .IP "\fILANG\fP" 10
  132. Provide a default value for the internationalization variables that are
  133. unset or null. (See the Base Definitions volume of POSIX.1\(hy2017,
  134. .IR "Section 8.2" ", " "Internationalization Variables"
  135. for the precedence of internationalization variables used to determine
  136. the values of locale categories.)
  137. .IP "\fILC_ALL\fP" 10
  138. If set to a non-empty string value, override the values of all the
  139. other internationalization variables.
  140. .IP "\fILC_CTYPE\fP" 10
  141. Determine the locale for the interpretation of sequences of bytes of
  142. text data as characters (for example, single-byte as opposed to
  143. multi-byte characters in arguments and input files), and for the
  144. determination of the width in column positions each character would
  145. occupy on a constant-width font output device.
  146. .IP "\fILC_MESSAGES\fP" 10
  147. .br
  148. Determine the locale that should be used to affect the format and
  149. contents of diagnostic messages written to standard error.
  150. .IP "\fINLSPATH\fP" 10
  151. Determine the location of message catalogs for the processing of
  152. .IR LC_MESSAGES .
  153. .SH "ASYNCHRONOUS EVENTS"
  154. Default.
  155. .SH STDOUT
  156. The standard output shall be a file containing a sequence of characters
  157. whose order shall be preserved from the input files, possibly with
  158. inserted
  159. <newline>
  160. characters.
  161. .SH STDERR
  162. The standard error shall be used only for diagnostic messages.
  163. .SH "OUTPUT FILES"
  164. None.
  165. .SH "EXTENDED DESCRIPTION"
  166. None.
  167. .SH "EXIT STATUS"
  168. The following exit values shall be returned:
  169. .IP "\00" 6
  170. All input files were processed successfully.
  171. .IP >0 6
  172. An error occurred.
  173. .SH "CONSEQUENCES OF ERRORS"
  174. Default.
  175. .LP
  176. .IR "The following sections are informative."
  177. .SH "APPLICATION USAGE"
  178. The
  179. .IR cut
  180. and
  181. .IR fold
  182. utilities can be used to create text files out of files with arbitrary
  183. line lengths. The
  184. .IR cut
  185. utility should be used when the number of lines (or records) needs to
  186. remain constant. The
  187. .IR fold
  188. utility should be used when the contents of long lines need to be kept
  189. contiguous.
  190. .P
  191. The
  192. .IR fold
  193. utility is frequently used to send text files to printers that
  194. truncate, rather than fold, lines wider than the printer is able to
  195. print (usually 80 or 132 column positions).
  196. .SH EXAMPLES
  197. An example invocation that submits a file of possibly long lines to the
  198. printer (under the assumption that the user knows the line width of the
  199. printer to be assigned by
  200. .IR lp ):
  201. .sp
  202. .RS 4
  203. .nf
  204. fold -w 132 bigfile | lp
  205. .fi
  206. .P
  207. .RE
  208. .SH RATIONALE
  209. Although terminal input in canonical processing mode requires the erase
  210. character (frequently set to
  211. <backspace>)
  212. to erase the previous character (not byte or column position), terminal
  213. output is not buffered and is extremely difficult, if not impossible,
  214. to parse correctly; the interpretation depends entirely on the physical
  215. device that actually displays/prints/stores the output. In all known
  216. internationalized implementations, the utilities producing output for
  217. mixed column-width output assume that a
  218. <backspace>
  219. character backs up one column position and outputs enough
  220. <backspace>
  221. characters to return to the start of the character when
  222. <backspace>
  223. is used to provide local line motions to support underlining and
  224. emboldening operations. Since
  225. .IR fold
  226. without the
  227. .BR \-b
  228. option is dealing with these same constraints,
  229. <backspace>
  230. is always treated as backing up one column position rather than backing
  231. up one character.
  232. .P
  233. Historical versions of the
  234. .IR fold
  235. utility assumed 1 byte was one character and occupied one column
  236. position when written out. This is no longer always true. Since the
  237. most common usage of
  238. .IR fold
  239. is believed to be folding long lines for output to limited-length
  240. output devices, this capability was preserved as the default case. The
  241. .BR \-b
  242. option was added so that applications could
  243. .IR fold
  244. files with arbitrary length lines into text files that could then be
  245. processed by the standard utilities. Note that although the width for
  246. the
  247. .BR \-b
  248. option is in bytes, a line is never split in the middle of a character.
  249. (It is unspecified what happens if a width is specified that is too
  250. small to hold a single character found in the input followed by a
  251. <newline>.)
  252. .P
  253. The tab stops are hardcoded to be every eighth column to meet
  254. historical practice. No new method of specifying other tab stops was
  255. invented.
  256. .SH "FUTURE DIRECTIONS"
  257. None.
  258. .SH "SEE ALSO"
  259. .IR "\fIcut\fR\^"
  260. .P
  261. The Base Definitions volume of POSIX.1\(hy2017,
  262. .IR "Chapter 8" ", " "Environment Variables",
  263. .IR "Section 12.2" ", " "Utility Syntax Guidelines"
  264. .\"
  265. .SH COPYRIGHT
  266. Portions of this text are reprinted and reproduced in electronic form
  267. from IEEE Std 1003.1-2017, Standard for Information Technology
  268. -- Portable Operating System Interface (POSIX), The Open Group Base
  269. Specifications Issue 7, 2018 Edition,
  270. Copyright (C) 2018 by the Institute of
  271. Electrical and Electronics Engineers, Inc and The Open Group.
  272. In the event of any discrepancy between this version and the original IEEE and
  273. The Open Group Standard, the original IEEE and The Open Group Standard
  274. is the referee document. The original Standard can be obtained online at
  275. http://www.opengroup.org/unix/online.html .
  276. .PP
  277. Any typographical or formatting errors that appear
  278. in this page are most likely
  279. to have been introduced during the conversion of the source files to
  280. man page format. To report such errors, see
  281. https://www.kernel.org/doc/man-pages/reporting_bugs.html .