Shell Getting Started Tutorial: Process Control (4) Case condition judgment

Source: Internet
Author: User

Syntax structure of case:

Case to test item in style string 1] command area 1;;( Style string 2) command area 2;; Style string 3) command area 3;; *) command area;; Esac
  • Command area, can be a single instruction or multi-line instruction, but the last command to be;; End.
  • Styles are available as string and wildcard characters, and are case-sensitive by default.
  • If the style serial has several strings to compare, use | Separated. Characters | There is a "or" meaning, that is, as long as one of them, even more successful.
  • Style serial can be written as ' (style serial) ', or omit left parenthesis, write ' style serial '. Generally, it is more popular to use the following notation.
  • Style *) is typically placed in the case where there is an area that captures all other situations that do not conform to the pattern.
  • Finally, end the case syntax with ESAC. Esac is the inverse of case.

Example:

#!/bin/bashread ynamecase $yname Injack | John | Joe) echo ' Well ... ' echo ' Long time no see. ' echo "How does do";;( Mary | Mary) echo ' Nice to meet you ';; c*) echo ' Long time to see. ';; *) echo ' hi! ';; Esac

Shell Getting Started Tutorial: Process Control (4) Case condition judgment

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.