November 2015
Beginner
282 pages
5h 5m
English
Switch is used to jump and run a certain case as per the result of the condition or expression is evaluated. It acts as an alternative to using multiple if in bash and keeps bash script much clear and readable.
The syntax of switch is as follows:
case $variable in pattern1) # Tasks to be executed ;; pattern2) # Tasks to be executed ;; … pattern n) # Tasks to be executed ;; *) esac
In syntax, $variable is the expression or value that needs to be matched among the list of choices provided.
In each choice, a pattern or a combination of patterns can be specified. The ;; tells bash that end of given choice block. The esac keyword specify end of case block.
The following is an example to count the number of files and directories in a ...
Read now
Unlock full access