Design a prompt menu for user selection, and perform operations and display based on user selection.
Menu: 1. Start vi Editor 2. Start x-windows and enter the graphic interface 3. Start the background printing process. 4. Exit ctrl + c.
#! /Bin/bash // call the execution environment
# Filename: qiantao // name of the script file
Echo "please choose :( 1-3, or ^ C) // select
Echo "1 vi" // display output 1 item
Echo "2 x-windows" // display output 2 x-windows
Echo "3 print-file" // display output print
Echo "ctrl + c quit" // display the end shortcut key
Read xyz // save user input in xyz
If [$ xyz = 1] // determines whether the condition is 1.
Then // if structure statement
Vi // enable vi
Exit 1 // exit the program
Elif [$ xyz = 2] // determines if xyz is 2
Then // nested if
Startx // start x-windows
Exit 1 // exit
Elif [$ xyz = 3] // whether to exit is equal to 3
Then // if statement nesting
Echo "" // enter the printed file name
Read filename // read the file name
Lp $ filename & // print the file
Exit 1 // exit Printing
Else // if statement
Echo "---------------------"
/Bin/sh qiantao. sh // call the nested script
Fi
Execution diagram:
The next step is successful.
This article is from the "Happy first" blog