Shell script if statement nested instance

Source: Internet
Author: User

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.