Skip to content

Instantly share code, notes, and snippets.

@quickgrid
Created April 1, 2016 05:42
Show Gist options
  • Save quickgrid/9210016c495189889d08b89eaed57d1c to your computer and use it in GitHub Desktop.
Save quickgrid/9210016c495189889d08b89eaed57d1c to your computer and use it in GitHub Desktop.
Bash switch case example.
#!/bin/bash
#swich case code
echo "yes or no?"
read answer
case "$answer" in
yes) echo "yay";;
no) echo "not";;
y) echo "yes?";;
n) echo "no?";;
*) echo "default case";;
esac
#combined switch case
echo "yes or no?"
read answer
case $answer in
yes|y|Yes|YES) echo "YAY";;
n*|N*) echo "NOT GOOD";;
*) echo "Default Case";;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment