Case and function of shell programming

Source: Internet
Author: User

I. Overview of CASE statements

Use case statements to rewrite if multiple branches to make the script structure clearer and more hierarchical

Perform different command sequences for different values of variables

The case statement is structured as follows:

Case Variable value in

Mode 1)

Command sequence 1

;;

Mode 2)

Command Sequence 2

;;

*)

Default command sequence

Esac

1 #!/bin/bash2Read-p"Please enter a character:"Key3Case"$key" inch4[a-z]| [A-z])#if the variable $key in 26 uppercase and lowercase letters5Echo"you entered the letter"6     ;;7[0-9])#if the variable $key in the number 0 to 98Echo"you have entered a number"9     ;;Ten*) OneEcho"you have entered a different function key" AEsac
Second, the case statement written by the program control script

The case statement is widely used to write program control scripts, with Chkconfig for controlling switches. This knowledge please refer to http://www.cnblogs.com/mangood/p/6033044.html

Third, Shell functions

The command sequence is written in a format so that it is easy to reuse the sequence of commands, and we call this sequence of commands as functions

(1) Definition of function: where [function] can be written and not written

[Function] Function name () {

Command sequence

[Return x]

}

(2) calling a function

function name [parameter 1] [parameter 2]

Case and function of shell programming

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.