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

read.1p (7611B)


  1. '\" et
  2. .TH READ "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. read
  12. \(em read from standard input into shell variables
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. read \fB[\fR-r\fB] \fIvar\fR...
  17. .fi
  18. .SH DESCRIPTION
  19. The
  20. .IR read
  21. utility shall read a single logical line from standard input into one
  22. or more shell variables.
  23. .P
  24. By default, unless the
  25. .BR \-r
  26. option is specified,
  27. <backslash>
  28. shall act as an escape character. An unescaped
  29. <backslash>
  30. shall preserve the literal value of the following character, with the
  31. exception of a
  32. <newline>.
  33. If a
  34. <newline>
  35. follows the
  36. <backslash>,
  37. the
  38. .IR read
  39. utility shall interpret this as line continuation. The
  40. <backslash>
  41. and
  42. <newline>
  43. shall be removed before splitting the input into fields. All other
  44. unescaped
  45. <backslash>
  46. characters shall be removed after splitting the input into fields.
  47. .P
  48. If standard input is a terminal device and the invoking shell is
  49. interactive,
  50. .IR read
  51. shall prompt for a continuation line when it reads an input line ending
  52. with a
  53. <backslash>
  54. <newline>,
  55. unless the
  56. .BR \-r
  57. option is specified.
  58. .P
  59. The terminating
  60. <newline>
  61. (if any) shall be removed from the input and the results shall be split
  62. into fields as in the shell for the results of parameter expansion (see
  63. .IR "Section 2.6.5" ", " "Field Splitting");
  64. the first field shall be assigned to the first variable
  65. .IR var ,
  66. the second field to the second variable
  67. .IR var ,
  68. and so on. If there are fewer fields than there are
  69. .IR var
  70. operands, the remaining
  71. .IR var s
  72. shall be set to empty strings. If there are fewer
  73. .IR var s
  74. than fields, the last
  75. .IR var
  76. shall be set to a value comprising the following elements:
  77. .IP " *" 4
  78. The field that corresponds to the last
  79. .IR var
  80. in the normal assignment sequence described above
  81. .IP " *" 4
  82. The delimiter(s) that follow the field corresponding to the last
  83. .IR var
  84. .IP " *" 4
  85. The remaining fields and their delimiters, with trailing
  86. .IR IFS
  87. white space ignored
  88. .P
  89. The setting of variables specified by the
  90. .IR var
  91. operands shall affect the current shell execution environment; see
  92. .IR "Section 2.12" ", " "Shell Execution Environment".
  93. If it is called in a subshell or separate utility execution
  94. environment, such as one of the following:
  95. .sp
  96. .RS 4
  97. .nf
  98. (read foo)
  99. nohup read ...
  100. find . -exec read ... \e;
  101. .fi
  102. .P
  103. .RE
  104. .P
  105. it shall not affect the shell variables in the caller's environment.
  106. .SH OPTIONS
  107. The
  108. .IR read
  109. utility shall conform to the Base Definitions volume of POSIX.1\(hy2017,
  110. .IR "Section 12.2" ", " "Utility Syntax Guidelines".
  111. .P
  112. The following option is supported:
  113. .IP "\fB\-r\fP" 10
  114. Do not treat a
  115. <backslash>
  116. character in any special way. Consider each
  117. <backslash>
  118. to be part of the input line.
  119. .SH OPERANDS
  120. The following operand shall be supported:
  121. .IP "\fIvar\fR" 10
  122. The name of an existing or nonexisting shell variable.
  123. .SH STDIN
  124. The standard input shall be a text file.
  125. .SH "INPUT FILES"
  126. None.
  127. .SH "ENVIRONMENT VARIABLES"
  128. The following environment variables shall affect the execution of
  129. .IR read :
  130. .IP "\fIIFS\fP" 10
  131. Determine the internal field separators used to delimit fields; see
  132. .IR "Section 2.5.3" ", " "Shell Variables".
  133. .IP "\fILANG\fP" 10
  134. Provide a default value for the internationalization variables that are
  135. unset or null. (See the Base Definitions volume of POSIX.1\(hy2017,
  136. .IR "Section 8.2" ", " "Internationalization Variables"
  137. for the precedence of internationalization variables used to determine
  138. the values of locale categories.)
  139. .IP "\fILC_ALL\fP" 10
  140. If set to a non-empty string value, override the values of all the
  141. other internationalization variables.
  142. .IP "\fILC_CTYPE\fP" 10
  143. Determine the locale for the interpretation of sequences of bytes of
  144. text data as characters (for example, single-byte as opposed to
  145. multi-byte characters in arguments).
  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. .IP "\fIPS2\fP" 10
  154. Provide the prompt string that an interactive shell shall write to
  155. standard error when a line ending with a
  156. <backslash>
  157. <newline>
  158. is read and the
  159. .BR \-r
  160. option was not specified.
  161. .SH "ASYNCHRONOUS EVENTS"
  162. Default.
  163. .SH STDOUT
  164. Not used.
  165. .SH STDERR
  166. The standard error shall be used for diagnostic messages and
  167. prompts for continued input.
  168. .SH "OUTPUT FILES"
  169. None.
  170. .SH "EXTENDED DESCRIPTION"
  171. None.
  172. .SH "EXIT STATUS"
  173. The following exit values shall be returned:
  174. .IP "\00" 6
  175. Successful completion.
  176. .IP >0 6
  177. End-of-file was detected or an error occurred.
  178. .SH "CONSEQUENCES OF ERRORS"
  179. Default.
  180. .LP
  181. .IR "The following sections are informative."
  182. .SH "APPLICATION USAGE"
  183. The
  184. .BR \-r
  185. option is included to enable
  186. .IR read
  187. to subsume the purpose of the
  188. .IR line
  189. utility, which is not included in POSIX.1\(hy2008.
  190. .SH EXAMPLES
  191. The following command:
  192. .sp
  193. .RS 4
  194. .nf
  195. while read -r xx yy
  196. do
  197. printf "%s %s\en$yy$xx"
  198. done < \fIinput_file\fR
  199. .fi
  200. .P
  201. .RE
  202. .P
  203. prints a file with the first field of each line moved to the end of the
  204. line.
  205. .SH RATIONALE
  206. The
  207. .IR read
  208. utility historically has been a shell built-in. It was separated off
  209. into its own utility to take advantage of the richer description of
  210. functionality introduced by this volume of POSIX.1\(hy2017.
  211. .P
  212. Since
  213. .IR read
  214. affects the current shell execution environment,
  215. it is generally provided as a shell regular built-in. If it is called
  216. in a subshell or separate utility execution environment, such as one of
  217. the following:
  218. .sp
  219. .RS 4
  220. .nf
  221. (read foo)
  222. nohup read ...
  223. find . -exec read ... \e;
  224. .fi
  225. .P
  226. .RE
  227. .P
  228. it does not affect the shell variables in the environment of the
  229. caller.
  230. .P
  231. Although the standard input is required to be a text file, and
  232. therefore will always end with a
  233. <newline>
  234. (unless it is an empty file), the processing of continuation lines
  235. when the
  236. .BR \-r
  237. option is not used can result in the input not ending with a
  238. <newline>.
  239. This occurs if the last line of the input file ends with a
  240. <backslash>
  241. <newline>.
  242. It is for this reason that ``if any'' is used in ``The terminating
  243. <newline>
  244. (if any) shall be removed from the input'' in the description.
  245. It is not a relaxation of the requirement for standard input to
  246. be a text file.
  247. .SH "FUTURE DIRECTIONS"
  248. None.
  249. .SH "SEE ALSO"
  250. .IR "Chapter 2" ", " "Shell Command Language"
  251. .P
  252. The Base Definitions volume of POSIX.1\(hy2017,
  253. .IR "Chapter 8" ", " "Environment Variables",
  254. .IR "Section 12.2" ", " "Utility Syntax Guidelines"
  255. .\"
  256. .SH COPYRIGHT
  257. Portions of this text are reprinted and reproduced in electronic form
  258. from IEEE Std 1003.1-2017, Standard for Information Technology
  259. -- Portable Operating System Interface (POSIX), The Open Group Base
  260. Specifications Issue 7, 2018 Edition,
  261. Copyright (C) 2018 by the Institute of
  262. Electrical and Electronics Engineers, Inc and The Open Group.
  263. In the event of any discrepancy between this version and the original IEEE and
  264. The Open Group Standard, the original IEEE and The Open Group Standard
  265. is the referee document. The original Standard can be obtained online at
  266. http://www.opengroup.org/unix/online.html .
  267. .PP
  268. Any typographical or formatting errors that appear
  269. in this page are most likely
  270. to have been introduced during the conversion of the source files to
  271. man page format. To report such errors, see
  272. https://www.kernel.org/doc/man-pages/reporting_bugs.html .