Skip to content

Instantly share code, notes, and snippets.

@domanchi
Last active August 25, 2018 14:09
Show Gist options
  • Save domanchi/2b049815001de4ed2cea95cddd972d3a to your computer and use it in GitHub Desktop.
Save domanchi/2b049815001de4ed2cea95cddd972d3a to your computer and use it in GitHub Desktop.
[switch statement] This is how to do switch statements in bash script #bash
#!/bin/bash
function main() {
case $1 in
a)
echo "You typed in 'a'!"
;;
b | 'd')
# This fallthrough operator is introduced in Bash v4.
# Otherwise, you need to use if statements.
echo "Fall through statement"
;&
c)
echo "You typed in 'c'?"
;;
*)
# This is the default case
echo "Usage: $0 {a|b|c|d}"
exit 1
esac
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment