Syntax

Bash Case Statement Syntax

In Bash, case statement: matches a value against patterns — case "$1" in start) ... ;; stop) ... ;; *) echo "usage" ;; esac

Quick Answer

Syntax
case "$1" in start) ... ;; stop) ... ;; *) echo "usage" ;; esac
BashSyntax

Case Statement

Code example
case "$1" in start) ... ;; stop) ... ;; *) echo "usage" ;; esac

Matches a value against patterns.

Learn More

How to case statement in Bash

  1. Open your Bash file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Bash Case Statement Syntax

Use case "$1" in start) ... ;; stop) ... ;; *) echo "usage" ;; esac.

Related Syntax References

Frequently asked questions

What is the Bash syntax for case statement?

Use this pattern: case "$1" in start) ... ;; stop) ... ;; *) echo "usage" ;; esac

Can I copy this Bash code example?

Yes. Use Copy code and adapt the example to your program.

Is this Bash syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify