case $VAR in val1) cmd1 ;; val2) cmd2 ;; *) default ;; esac

Category: Bash Scripting

case $VAR in val1) cmd1 ;; val2) cmd2 ;; *) default ;; esac

Case statement for matching variable against patterns

A case statement matches a variable against multiple patterns — cleaner than many if/elif/else chains.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.