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

break.1p (5628B)


  1. '\" et
  2. .TH BREAK "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. break
  12. \(em exit from for, while, or until loop
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. break \fB[\fIn\fB]\fR
  17. .fi
  18. .SH DESCRIPTION
  19. If
  20. .IR n
  21. is specified, the
  22. .IR break
  23. utility shall exit from the
  24. .IR n th
  25. enclosing
  26. .BR for ,
  27. .BR while ,
  28. or
  29. .BR until
  30. loop. If
  31. .IR n
  32. is not specified,
  33. .IR break
  34. shall behave as if
  35. .IR n
  36. was specified as 1. Execution shall continue with the command
  37. immediately following the exited loop. The value of
  38. .IR n
  39. is a positive decimal integer. If
  40. .IR n
  41. is greater than the number of enclosing loops, the outermost enclosing
  42. loop shall be exited. If there is no enclosing loop, the behavior is
  43. unspecified.
  44. .P
  45. A loop shall enclose a
  46. .IR break
  47. or
  48. .IR continue
  49. command if the loop lexically encloses the command. A loop lexically
  50. encloses a
  51. .IR break
  52. or
  53. .IR continue
  54. command if the command is:
  55. .IP " *" 4
  56. Executing in the same execution environment (see
  57. .IR "Section 2.12" ", " "Shell Execution Environment")
  58. as the compound-list of the loop's do-group (see
  59. .IR "Section 2.10.2" ", " "Shell Grammar Rules"),
  60. and
  61. .IP " *" 4
  62. Contained in a compound-list associated with the loop (either in the
  63. compound-list of the loop's do-group or, if the loop is a
  64. .BR while
  65. or
  66. .BR until
  67. loop, in the compound-list following the
  68. .BR while
  69. or
  70. .BR until
  71. reserved word), and
  72. .IP " *" 4
  73. Not in the body of a function whose function definition command (see
  74. .IR "Section 2.9.5" ", " "Function Definition Command")
  75. is contained in a compound-list associated with the loop.
  76. .P
  77. If
  78. .IR n
  79. is greater than the number of lexically enclosing loops and there is a
  80. non-lexically enclosing loop in progress in the same execution
  81. environment as the
  82. .IR break
  83. or
  84. .IR continue
  85. command, it is unspecified whether that loop encloses the command.
  86. .SH OPTIONS
  87. None.
  88. .SH OPERANDS
  89. See the DESCRIPTION.
  90. .SH STDIN
  91. Not used.
  92. .SH "INPUT FILES"
  93. None.
  94. .SH "ENVIRONMENT VARIABLES"
  95. None.
  96. .SH "ASYNCHRONOUS EVENTS"
  97. Default.
  98. .SH STDOUT
  99. Not used.
  100. .SH STDERR
  101. The standard error shall be used only for diagnostic messages.
  102. .SH "OUTPUT FILES"
  103. None.
  104. .SH "EXTENDED DESCRIPTION"
  105. None.
  106. .SH "EXIT STATUS"
  107. .IP "\00" 6
  108. Successful completion.
  109. .IP >0 6
  110. The
  111. .IR n
  112. value was not an unsigned decimal integer greater than or equal to 1.
  113. .SH "CONSEQUENCES OF ERRORS"
  114. Default.
  115. .LP
  116. .IR "The following sections are informative."
  117. .SH "APPLICATION USAGE"
  118. None.
  119. .SH EXAMPLES
  120. .LP
  121. .nf
  122. for i in *
  123. do
  124. if test -d "$i"
  125. then break
  126. fi
  127. done
  128. .fi
  129. .P
  130. The results of running the following example are unspecified: there
  131. are two loops in progress when the
  132. .IR break
  133. command is executed, and they are in the same execution environment,
  134. but neither loop is lexically enclosing the
  135. .IR break
  136. command. (There are no loops lexically enclosing the
  137. .IR continue
  138. commands, either.)
  139. .LP
  140. .nf
  141. foo() {
  142. for j in 1 2; do
  143. echo \(aqbreak 2\(aq >/tmp/do_break
  144. echo " sourcing /tmp/do_break ($j)..."
  145. # the behavior of the break from running the following command
  146. # results in unspecified behavior:
  147. . /tmp/do_break
  148. .P
  149. do_continue() { continue 2; }
  150. echo " running do_continue ($j)..."
  151. # the behavior of the continue in the following function call
  152. # results in unspecified behavior (if execution reaches this
  153. # point):
  154. do_continue
  155. .P
  156. trap \(aqcontinue 2\(aq USR1
  157. echo " sending SIGUSR1 to self ($j)..."
  158. # the behavior of the continue in the trap invoked from the
  159. # following signal results in unspecified behavior (if
  160. # execution reaches this point):
  161. kill -s USR1 $$
  162. sleep 1
  163. done
  164. }
  165. for i in 1 2; do
  166. echo "running foo ($i)..."
  167. foo
  168. done
  169. .fi
  170. .SH "RATIONALE"
  171. In early proposals, consideration was given to expanding the syntax of
  172. .IR break
  173. and
  174. .IR continue
  175. to refer to a label associated with the appropriate loop as a
  176. preferable alternative to the
  177. .IR n
  178. method. However, this volume of POSIX.1\(hy2017 does reserve the name space of command names
  179. ending with a
  180. <colon>.
  181. It is anticipated that a future implementation could take advantage of
  182. this and provide something like:
  183. .sp
  184. .RS 4
  185. .nf
  186. outofloop: for i in a b c d e
  187. do
  188. for j in 0 1 2 3 4 5 6 7 8 9
  189. do
  190. if test -r "${i}${j}"
  191. then break outofloop
  192. fi
  193. done
  194. done
  195. .fi
  196. .P
  197. .RE
  198. .P
  199. and that this might be standardized after implementation experience is
  200. achieved.
  201. .SH "FUTURE DIRECTIONS"
  202. None.
  203. .SH "SEE ALSO"
  204. .IR "Section 2.14" ", " "Special Built-In Utilities"
  205. .\"
  206. .SH COPYRIGHT
  207. Portions of this text are reprinted and reproduced in electronic form
  208. from IEEE Std 1003.1-2017, Standard for Information Technology
  209. -- Portable Operating System Interface (POSIX), The Open Group Base
  210. Specifications Issue 7, 2018 Edition,
  211. Copyright (C) 2018 by the Institute of
  212. Electrical and Electronics Engineers, Inc and The Open Group.
  213. In the event of any discrepancy between this version and the original IEEE and
  214. The Open Group Standard, the original IEEE and The Open Group Standard
  215. is the referee document. The original Standard can be obtained online at
  216. http://www.opengroup.org/unix/online.html .
  217. .PP
  218. Any typographical or formatting errors that appear
  219. in this page are most likely
  220. to have been introduced during the conversion of the source files to
  221. man page format. To report such errors, see
  222. https://www.kernel.org/doc/man-pages/reporting_bugs.html .