What it does: Matches patterns cleanly (e.g., commands or file extensions) without long chains of if/elif
.
What is it? case
is a cleaner alternative to long chains of if/elif
when matching against patterns.
#!/bin/bash
action="$1"
case "$action" in
start) echo "Startingā¦";;
stop) echo "Stoppingā¦";;
restart) echo "Restartingā¦";;
*) echo "Usage: $0 {start|stop|restart}"; exit 1;;
esac