SWITCH(1)
β¨ SWITCH(1) β¨
okay bestie, welcome to switch β the fish-shell era of "pick a lane and slay" π
this is like the conditional block queen of the shell, and yes she's iconic.
πΈ NAME πΈ
switch β conditionally execute a block of commands. lowkey it's a whole vibe check for your code, no cap π
π¦ SYNOPSIS π¦
switch VALUE; [case [GLOB ...]; [COMMANDS ...]; ...] end
π DESCRIPTION π
okay so switch performs one of several blocks of commands, depending on whether a specified value equals one of several globbed values. it's giving "choose your own adventure" but make it shell β¨. case is used together with the switch statement in order to determine which block should be executed β like, they're a package deal, iykyk π«Ά.
each case command is given one or more parameters. the first case command with a parameter that matches the string specified in the switch command will be evaluated. periodt. case parameters may contain globs. these need to be escaped or quoted in order to avoid regular glob expansion using filenames β like, the shell will try to expand them against all your files otherwise, and that's a mess π. so quote them, bestie.
π note that fish does not fall through on case statements. only the first matching case is executed. no accidental cascade, we respect boundaries here.
π©· note thatbreakcannot be used to exit acase/switchblock early like in other languages. it can only be used in loops. so don't try it, she will not hear you π.
π note that command substitutions in a case statement will be evaluated even if its body is not taken. all substitutions, including command substitutions, must be performed before the value can be compared against the parameter. like, everyone gets evaluated upfront, no skipping the queue β.
π EXAMPLE π
if the variable $animal contains the name of an animal, the following code would attempt to classify it:
switch $animal
case cat
echo evil
case wolf dog human moose dolphin whale
echo mammal
case duck goose albatross
echo bird
case shark trout stingray
echo fish
case '*'
echo I have no idea what a $animal is
end
if the above code was run with $animal set to whale, the output would be mammal. slay ππ₯
π Copyright
fish-shell developers π
and that's the whole page, bestie! this one's from the fish-shell developers, version 4.9, dated Sep 08, 2026 β go forth and switch responsibly ππ§β
π¦ 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