Case Statement
SH · Bash Scriptingsyntax
case $variable in
pattern1) commands ;;
pattern2) commands ;;
*) default ;;
esacexample
case "$1" in
start)
echo "Starting service..."
systemctl start myapp
;;
stop|restart)
echo "${1}ing service..."
systemctl "$1" myapp
;;
status)
systemctl status myapp
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esacNote Each branch ends with ;;. Patterns support globbing and | for alternatives. case is cleaner than long if/elif chains when matching a single variable against many values. *) is the default/catch-all branch.