September 2018
Beginner
186 pages
4h 30m
English
Bash's extension to string equality tests for pattern matching is useful, but it can sometimes be more convenient to use the older POSIX-specified case construct, which is shell script's analogue of the C switch statement.
The case statement allows us to run commands based on the outcome of matching a string against glob patterns. For example, to check whether the command variable matches help, we might do this:
case $command in
help) printf 'Command help:\n...' ;;
esac
Note the following details of this syntax:
Read now
Unlock full access