Case Statement in Shell
Level 3141 keystrokes
case compares the value of action with each pattern in order and runs the first match. Here action is "start", so it prints "Starting service...".
Shell code
# The value that case will test1action="start"# Compare $action with each pattern from top to bottom2case $action in # Matches "start"; ;; ends this branch3 start) echo "Starting service..." ;; # Matches "stop"4 stop) echo "Stopping service..." ;; # * matches anything else (default branch)5 *) echo "Unknown action" ;;# esac (case spelled backwards) closes the case6esacOutput
Starting service...
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Shell code and how often they appear.
"× 8;× 6.× 6)× 3*× 1=× 1$× 1