"Shell" Linux Shell Case detailed

Source: Internet
Author: User
Tags case statement

In general, case is a judgment statement that is easier to understand than if.

Case Statement Format

case in 变量 值1)    内容 ;;值2)    内容 ;;esac

Note: Each content needs to be added after;; , can be written across rows or peers.

Instance: Executes the statement based on the selection entered by the user.

#!/bin/bash -# 打印选择菜单cat <<EOF        Option:        1) restart networking service.        2) start networking service.        3) stop networking service.        *) exit.EOFread -p "Please enter a option:" number# 使用case语句对参数进行判断case $number in1)        echo "The Networking service is restart,wait......" ;;2)        echo "The Networking service is start,wait......" ;;3)        echo "The Networking service is stop,wait......" ;;*)        echo "exit."  ;;esac

[Email protected] scripts]# bash case.sh
Option:
1) Restart networking service.
2) Start networking service.
3) Stop networking service.
*) exit.
Please enter a option:1
The Networking service is restart,wait ...

All rights reserved: Arppinging

"Shell" Linux Shell Case detailed

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.