.\" 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 "CASE" "1" "Nov 10, 2025" "4.2" "fish-shell"
.SH NAME
case \- conditionally execute a block of commands
.SH SYNOPSIS
.nf
\fBswitch\fP \fIVALUE\fP
   [\fBcase\fP [\fIGLOB\fP \&...]
       [\fICOMMAND\fP \&...]]
\fBend\fP
.fi
.sp
.SH DESCRIPTION
.sp
\fBswitch\fP executes one of several blocks of commands, depending on whether a specified value matches one of several values. \fBcase\fP is used together with the \fBswitch\fP statement in order to determine which block should be executed.
.sp
Each \fBcase\fP command is given one or more parameters. The first \fBcase\fP command with a parameter that matches the string specified in the switch command will be evaluated. \fBcase\fP parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames.
.sp
Note that fish does not fall through on case statements. Only the first matching case is executed.
.sp
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.
.SH EXAMPLE
.sp
Say $animal contains the name of an animal. Then this code would classify it:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
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 \(aq*\(aq
        echo I have no idea what a $animal is
end
.EE
.UNINDENT
.UNINDENT
.sp
If the above code was run with \fB$animal\fP set to \fBwhale\fP, the output
would be \fBmammal\fP\&.
.sp
If \fB$animal\fP was set to \(dqbanana\(dq, it would print \(dqI have no idea what a banana is\(dq.
.SH COPYRIGHT
fish-shell developers
.\" Generated by docutils manpage writer.
.
