Last active
August 25, 2018 14:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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