- case
- esac
case
examples/script/case.sh
#!/bin/bash case "$1" in "foo") echo "it is foo";; [a-z][a-z][a-z]) echo "3 letters";; [0-9][0-9]) echo "2 digits";; 42) echo "the answer";; *) echo "default";; esac
$ ./examples/script/case.sh foo it is foo $ ./examples/script/case.sh abc letters $ ./examples/script/case.sh 123 digits $ ./examples/script/case.sh 42 digits $ ./examples/script/case.sh default $ ./examples/script/case.sh abc123 letters
- ;; - no subsequent cases are checked
- ;& - execute the subsequent blocks until ;; is found or till the esac.
- ;;& - check the subsequent condition till you find a match.