First, the grammar
Case inch " content of the first variable " # Each variable content is suggested in double quotation marks, the keyword is parentheses) # execution content ;; # Use two consecutive semicolons to handle each category end! " content of the second variable " ) # execution content ;; *) # The last variable content will use * to represent all other values, but does not contain the contents of the first variable with the second variable contents of the other program run segment # execution content ;; Esac Case
Second, practice
- Simulating Linux startup scripts
status=0#0: Start;1: Stop Case " $" inch"Start") Echo "* Program is running" ;;"Stop") Echo "* Stopping program" ;;"Status") Echo "* Program is running" ;;"Restart") Echo "* Stopping program" Echo "* Program is running" ;;*) Echo "Plz input [Start|stop|status|restart]" ;;Esac
[Email protected]:~$./test. SH Start* program is running[email protected]:~$./test. SH Stop* stopping program[email protected]:~$./test. SH Status* program is running[email protected]:~$./test. SH Restart* stoppingprogram * is running[email protected]:~$./test. SH Plz input [start|stop|status| Restart] [Email protected]:~$
Case exercises based on Shell programming