Case statements
Choose a clear action from a small set of supported words.
Match alternatives explicitly
A case statement compares one value against shell patterns. Each branch ends with ;;; the whole statement ends with esac. The patterns are globs, not regular expressions. A final * branch is a useful place to reject unsupported inputs.
Write start|START) when those are the two supported spellings. This does not automatically accept every mixture of letter case. Be deliberate about normalization and explain what your interface accepts. Do not use Bash 4 case-conversion expansions when targeting Bash 3.2.
A small command interface
A script can offer a default action and a few explicit alternatives. Invalid actions should produce a useful diagnostic on stderr and a nonzero status; they should not silently choose a destructive default. Quotes remain necessary when passing the selected value to another command.
This lesson prints proposed actions only. It does not start or stop a real service. The exercise is about control flow and interface design, skills you can later apply to tools in an environment you administer. Browser Linux commands and the saved virtual workspace remain separate from your own operating system.
action=${1:-status}
case "$action" in
status) printf 'Inspect the current state\n' ;;
start|stop) printf 'Proposed action: %s\n' "$action" ;;
*) printf 'Unsupported action\n' >&2; exit 2 ;;
esac
Put it into practice.
Accept `start`, `stop` or `status` as argument 1, with `status` as the default. Also accept the all-uppercase spelling of each. Print `action=<lowercase action>` and exit 0. Reject any other value with `Supported actions: start, stop, status` on stderr and exit 2. Do not run service-control commands.
See an explained solution
action=${1:-status}
case "$action" in
start|START) action=start ;;
stop|STOP) action=stop ;;
status|STATUS) action=status ;;
*) printf 'Supported actions: start, stop, status\n' >&2; exit 2 ;;
esac
printf 'action=%s\n' "$action"
The supported inputs are explicit and the default is observational. The catch-all branch rejects surprises before any action could occur.