Shell Foundation and Process Control statements case judgment

Source: Internet
Author: User
Tags case statement

The Last Post describes the while statement, while the basic use and the dead loop and the file test method, and so on, or that sentence if you want to master all the need to practice many times.

This blog introduces the case statement, the streamlined if statement, because the judgment written with the application will be much shorter than if.

Case Syntax Format:

Case variable reference in

Variable value)

Execute statement;;

Second value of a variable)

Execute statement;;

Esac

If you have more than one value, you can always call the above format and end with ESAC. The case can also use wildcards, which are supported by the following wildcard characters:

*: Any character of any length

? : Any single character

[]: Any single character within the specified range

A|b:a or B

Here is a small topic is a random number $random said that the random number is actually a pseudo-random number, its range is: 0-32767. If you call, you can enter $random directly.

There's not much to say, just go to the instance stage.

Let's have a simple one. It's hard to understand. Determine whether the value of $ A is 1 or 100 if 1 is output $ A if 100 is output 100, and the other is output wrong

#!/bin/bash

For a in {1..100};d o

Case $a in

1)

echo $a;;

100)

echo $a;;

*)

echo "Wrong"

Esac

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/54/72/wKioL1SC47TjEjd4AAE8bQvjFj4018.jpg "title=" 2014-12-06 19:05:59 screen. png "alt=" wkiol1sc47tjejd4aae8bqvjfj4018.jpg "/>

The result of the operation is the first row output 1 line 100th output 100 The rest is all wrong

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/54/72/wKioL1SC4_ugWyysAAFV-izEa24870.jpg "title=" 2014-12-06 19:07:10 screen. png "alt=" wkiol1sc4_ugwyysaafv-izea24870.jpg "/>

Just write here, because it feels so easy. These loop control statements can be used quickly as long as the logical relationship is understood.

This article is from the "Yxn" blog, make sure to keep this source http://jyxnt.blog.51cto.com/9581167/1587145

Shell Foundation and Process Control statements case 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.