CASE(1)
πΈ case(1) π β the fish-shell manual, bestie edition πβ¨
okay so real quick: this is case(1) from fish-shell, and it's genuinely one of the cutest little building blocks in the whole shell, so buckle up π
β¨ NAME β¨
case β conditionally execute a block of commands π¦
like, it's the "which one of these applies to me" girlie of the shell. main character energy fr.
π SYNOPSIS π
switch VALUE
[case [GLOB ...]
[COMMAND ...]]
end
look at her. iconic structure. switch opens the whole thing, case sits in the middle doing the vibe check, end closes it out. periodt π
π DESCRIPTION π
okay bestie, so here's the tea β
switch executes one of several blocks of commands β which block it picks depends on whether a specified value matches one of several values. and case is the bestie that works together with the switch statement to figure out which block should actually be executed π«Ά
each case command is given one or more parameters. and here's the rule: the first case command with a parameter that matches the string specified in the switch command will be evaluated. first one wins, no arguments π
case parameters may contain wildcards! yesss glob vibes β¨ but heads up β these need to be escaped or quoted in order to avoid regular wildcard expansion using filenames. so if you want the wildcard to stay a wildcard, you gotta protect it. quote your girlies, fr fr π
π big one: fish does not fall through on case statements. only the first matching case is executed. no accidental slide into the next block, no chaos. she's not messy like that.
π another important one: command substitutions in a case statement will be evaluated even if its body is not taken. yes, even then. all substitutions, including command substitutions, must be performed before the value can be compared against the parameter. so the substitutions run first, comparison happens after β that's just the order of operations, no cap.
π EXAMPLE π
say $animal contains the name of an animal. then this code would 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
# Note that the next case has a wildcard which is quoted
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 πβ¨
if $animal was set to "banana", it would print I have no idea what a banana is ππ β and honestly? relatable. the quoted '*' catch-all ate that one right up.
π Copyright π
fish-shell developers π
and that's the whole page, bestie! πΈ this was case(1), from fish-shell version 4.9, dated Sep 08, 2026 β go forth and switch responsibly, mwah ππ¦β
π¦ 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