FOR(1)

✨ FOR(1) β€” the fish-shell loop that eats πŸ’…

okay bestie so this is for from the fish-shell manual set, page one of the iconic franchise, and honestly? it's giving "tiny syntax, huge power" πŸ”₯ no cap, this is the little loop that could and it's about to carry your whole script fr fr.


🌸 SYNOPSIS 🌸

for VARNAME in [VALUES ...]; COMMANDS ...; end

like, that's it. that's the whole vibe check. πŸŽ€


πŸ’œ DESCRIPTION πŸ’œ

so for is a loop construct β€” it runs the commands you give it in COMMANDS over and over, multiple times, once for each value. on every single iteration, the local variable named by VARNAME gets handed a brand-new value from VALUES. slay.

and if VALUES is empty? then COMMANDS literally does not get executed at all. not once. zero. πŸ’€ empty list = no iterations, periodt.

here's the part people always get confused about (iykyk): VARNAME is visible after the loop terminates, and it holds the last value that got assigned to it. the variable doesn't just vanish into the void when end hits, okay? πŸ‘‘

and if VARNAME doesn't already exist? it gets set in the local scope. for our purposes though, the rules go like this:

  • if the for block is inside a function, there must be a local variable with the same name. ✨
  • if the for block is not nested inside a function, then global and universal variables with the same name will be used, if they exist. πŸ¦‹

also much like set, for does not modify $status β€” but the evaluation of the commands underneath it totally can. so keep an eye on that bestie. πŸ‘€

and if you're ever stuck (no shame, we've all been there), the -h or --help option displays help about using this command. 🫢


πŸŽ€ EXAMPLE πŸŽ€

look at her go:

for i in foo bar baz; echo $i; end

# would output:
foo
bar
baz

iconic. ate and left no crumbs. πŸ’…


πŸ¦‹ NOTES πŸ¦‹

okay so history lesson time and it matters, so listen up: the VARNAME was local to the for block in releases prior to 3.0.0. which means the variable did not survive the loop the way it does now. 😭

if you did something like this:

for var in a b c
    if break_from_loop
        break
    end
end
echo $var

then the last value assigned to var when the loop terminated would not be available outside the loop. so what echo $var would write depended entirely on whatever var was set to before the loop was run. and in practice? likely nothing. 🫠

so yeah β€” old fish, different rules. mind the version, bestie. ⭐


fish-shell developers 🧚


and that's the whole page, bestie! this little beauty is from fish-shell β€” version 4.9, dated Sep 08, 2026 β€” so go forth, loop your hearts out, and remember: your VARNAME will still be there for you when it's over. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from
  • arch rolling: fish 4.9.3-1 Β· GPL-2.0-only AND BSD-3-Clause AND ISC AND MIT AND PSF-2.0
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms