Shell script: Case

Source: Internet
Author: User
Tags case statement

Case ... Esac is similar to the switch ... case statement in other languages, and is a multi-branch selection structure.

Syntax for Case statements

 Case inch mode 1)    Command1    command2    command3    ; Mode 2)    Command1    command2    command3    ;; *)    Command1    command2    command3    ;; Esac

The value must be followed by the keyword in, and each pattern must end with a closing parenthesis. among them;; Similar to break in other languages

Here is an example of a case

#!/bin/bash
Echo 'Input A number between 1 to 4'Echo-E'Your number is:\c'Read Anum Case$aNuminch 1)Echo 'You select 1' ;; 2)Echo 'You select 2' ;; 3)Echo 'You select 3' ;; 4)Echo 'You Select 4' ;; *)Echo 'You does not select a number between 1 to 4' ;;Esac

Shell script: Case

Related Article

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.