case statement

A statement that compares one value against several glob patterns and runs the block for the first that matches.

In more detail

Each pattern ends with ) and each block with ;;, alternatives are separated by |, and * matches anything as a final default. esac, case backwards, closes it. It reads more clearly than a long chain of elif tests on the same value.

Example

case "$file" in *.txt | *.md) echo text ;; *) echo unknown ;; esac

Related terms

Taught in

References