.\" 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 "FOR" "1" "Nov 13, 2025" "4.2" "fish-shell" .SH NAME for \- perform a set of commands multiple times .SH SYNOPSIS .nf \fBfor\fP \fIVARNAME\fP \fBin\fP [\fIVALUES\fP \&...]\fB;\fP \fICOMMANDS\fP \&...\fB;\fP \fBend\fP .fi .sp .SH DESCRIPTION .sp \fBfor\fP is a loop construct. It will perform the commands specified by \fICOMMANDS\fP multiple times. On each iteration, the local variable specified by \fIVARNAME\fP is assigned a new value from \fIVALUES\fP\&. If \fIVALUES\fP is empty, \fICOMMANDS\fP will not be executed at all. The \fIVARNAME\fP is visible when the loop terminates and will contain the last value assigned to it. If \fIVARNAME\fP does not already exist it will be set in the local scope. For our purposes if the \fBfor\fP block is inside a function there must be a local variable with the same name. If the \fBfor\fP block is not nested inside a function then global and universal variables of the same name will be used if they exist. .sp Much like \fI\%set\fP, \fBfor\fP does not modify $status, but the evaluation of its subordinate commands can. .sp The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command. .SH EXAMPLE .INDENT 0.0 .INDENT 3.5 .sp .EX for i in foo bar baz; echo $i; end # would output: foo bar baz .EE .UNINDENT .UNINDENT .SH NOTES .sp The \fBVARNAME\fP was local to the for block in releases prior to 3.0.0. This means that if you did something like this: .INDENT 0.0 .INDENT 3.5 .sp .EX for var in a b c if break_from_loop break end end echo $var .EE .UNINDENT .UNINDENT .sp The last value assigned to \fBvar\fP when the loop terminated would not be available outside the loop. What \fBecho $var\fP would write depended on what it was set to before the loop was run. Likely nothing. .SH COPYRIGHT fish-shell developers .\" Generated by docutils manpage writer. .