Example of a case statement in a Linux bash Shell _linux Shell

Source: Internet
Author: User
Tags case statement

Example of a bash case statement.

Sharing a bash shell code is helpful in understanding the use of case statements by students who learn about bash.

Example:

Copy Code code as follows:

#!/bin/bash
##
# program:
# File operation
# 1.) Open file 2.) Display file 3.) Edit file 4.) Delete file
# Site:WWW.JB51.NET
Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
Export PATH
echo "---------------------------------"
echo "List of item to operate file-"
echo "---------------------------------"
echo "1). Open a file-"
echo "2). Display a file-"
echo "3). Edit a file-"
echo "4). Delete a file-"
echo "---------------------------------"
Read Select
Case $select in
1)
echo "Do Open file operation"

2)
echo "Do display a file operation"

3)
echo "Do edit a file operation"

4)
echo "Do delete a file operation"

*)
echo "There is no to do!"
Exit 1

Esac

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.