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.


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