.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "BEGIN" "1" "Nov 13, 2025" "4.2" "fish-shell" .SH NAME begin \- start a new block of code .SH SYNOPSIS .nf \fBbegin\fP\fB;\fP [\fICOMMANDS\fP \&...]\fB;\fP \fBend\fP \fB{ \fP[\fICOMMANDS\fP \&...]\fB }\fP .fi .sp .SH DESCRIPTION .sp \fBbegin\fP is used to create a new block of code. .sp A block allows the introduction of a new \fI\%variable scope\fP, redirection of the input or output of a set of commands as a group, or to specify precedence when using the conditional commands like \fBand\fP\&. .sp The block is unconditionally executed. \fBbegin; ...; end\fP is equivalent to \fBif true; ...; end\fP\&. .sp \fBbegin\fP does not change the current exit status itself. After the block has completed, \fB$status\fP will be set to the status returned by the most recent command. .sp Some other shells only support the \fB{ [COMMANDS ...] ; }\fP notation. .sp The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command. .SH EXAMPLE .sp The following code sets a number of variables inside of a block scope. Since the variables are set inside the block and have local scope, they will be automatically deleted when the block ends. .INDENT 0.0 .INDENT 3.5 .sp .EX begin set \-l PIRATE Yarrr ... end echo $PIRATE # This will not output anything, since the PIRATE variable # went out of scope at the end of the block .EE .UNINDENT .UNINDENT .sp In the following code, all output is redirected to the file out.html. .INDENT 0.0 .INDENT 3.5 .sp .EX begin echo $xml_header echo $html_header if test \-e $file ... end ... end > out.html .EE .UNINDENT .UNINDENT .SH COPYRIGHT fish-shell developers .\" Generated by docutils manpage writer. .