Shell script Programming--case statements

Source: Internet
Author: User
Tags case statement

What I'm sharing for you is how to use case statements to write some scripts that you choose to execute. Case statements are mainly adapted for use in some complex selection of scripts, if we use if multi-branch statements can also be written out, but obviously too shiver, at this time our best choice is the case statement.

Conditional Judgment: Case statement
Case variable reference in
PAT1)
Branch 1
;;
PAT2)
Branch 2
;;
...
*)
Default Branch
;;
Esac

Example code:

1 #!/bin/bash
2
3 #Author: Wangjun
4 #Version: 1.0
5 #Create time:2016-08-14 09:56:23
6 #Description: Casetest
7
8 echo "C=create;o=open;d=delet;m=modify"
9 Read-p "Please choose:" Choose
"$choose" in
c)
echo "Create file"
13;;
+ O)
echo "Open file"
16;;
(d)
echo "Delet file"
19;;
(m)
echo "Modify file"
22;;
23 *)
echo "Error input"
25;;
Esac

Execution effect:

650) this.width=650; "title=" Casetest.png "style=" Float:none "src=" http://s5.51cto.com/wyfs02/M02/85/EF/ Wkiol1ev6ghrnkkxaabhm5dum8u575.png "alt=" Wkiol1ev6ghrnkkxaabhm5dum8u575.png "/>

650) this.width=650; "title=" Casetest2.png "style=" Float:none "src=" http://s1.51cto.com/wyfs02/M00/85/EF/ Wkiom1ev6gldvadmaabx5pcwa8i503.png "alt=" Wkiom1ev6gldvadmaabx5pcwa8i503.png "/>

About the use of the case statement is simple to share so much, of course, all bloggers of the blogger, will be updated at any time, I hope you can look back.

This article is from the "Love Firewall" blog, be sure to keep this source http://183530300.blog.51cto.com/894387/1837755

Shell script Programming--case statements

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.