First, the grammar
Select inch con1 con2 con3 # automatically lists Con1,con2,con3 's selection menu do #执行内容break # Select itself is a loop, Break is when you choose to jump out of the loop done
Second, practice
- Select + Case Emulation Linux startup script
functionProgramstatus () {if[" $"-eq0]; Then Echo "* Program is running" Else Echo "* program has stopped" fi}status=0#0: Start;1: StopSelectPinch "Start" "Stop" "Status" "Restart" "*" "" Do Case "$p" inch"Start") Status=0programstatus $status;;"Stop") Status=1programstatus $status;;"Status") programstatus $status;;"Restart") if["$status"-eq0]; ThenStatus=1 Echo "* program has stopped" fiStatus=0 Echo "* Program is running" ;;"") break;;*) Echo "Plz input [Start|stop|status|restart]" ;;Esac Done
[email protected]:~$./test. sh 1 ) start 2 ) stop 3 Status 4 ) restart 5 ) # ? 1 * program is running# ? 2 * program has stopped# ? 3 * program has stopped# ? 4 * program is running# ? 5 [email protected]: ~$
Shell Programming Basics of Select Exercise