case in Bash

From the Bash Scripting cheat sheet · case Statements · verified Jul 2026

case

Match a value against patterns.

bash
# Quick Reference
case "$1" in
    start) echo "starting" ;;
    stop)  echo "stopping" ;;
    *)     echo "usage: start|stop" ;;
esac
💡 case matches glob patterns (not regex): * ? [..] and | for alternatives.
⚡ Each branch ends with ;; - forgetting it is a common syntax error.
📌 The *) branch is the catch-all default - put it last.
🟢 case is cleaner than a long if/elif chain when branching on one value.
casebranching

Continue with Bash Scripting

Save the full cheat sheet or work through every related task.

Back to the full Bash Scripting cheat sheet