Bash case Statements
case is a clean alternative to lots of if/elif tests when matching patterns.
Example
#!/bin/bash
action="$1"
case "$action" in
start) echo "Starting…";;
stop) echo "Stopping…";;
restart) echo "Restarting…";;
*) echo "Usage: $0 {start|stop|restart}"; exit 1;;
esacHow to run it
- Save it to a file.
- Run
chmod +x filename.shwhere applicable. - Run it from the terminal.