Automation, Orchestration, and Scripting
A service wrapper script uses case "$1" in with the first pattern *) echo "Usage: $0 start|stop"; ;; followed by start) and stop) branches. Running the script with start only prints the usage message. What is the cause, and how is it fixed?
Show the answer
Correct answerC. The * pattern matches every value and the first match wins, so it must be moved to the last position
A case statement runs the first pattern that matches and then stops, so a leading * catches every argument. Placing *) last makes it the default. Double brackets are not used in case patterns, and ;; ends the case rather than continuing to later patterns.