Linux Gvim Shell CASE...ESAC statement

Source: Internet
Author: User
Tags case statement

#case: ESAC statement: with switch. Case similar, is a multi-branch selection structure
#case语句匹配一个值或一个模式 if the match succeeds in executing the corresponding command, if the match does not execute the * command successfully
#;; Similar to break, the delegate jumps to the end of the entire case statement
#case value in
#模式1)
# Command1
#    ;;
#模式2)
# Command1
#    ;;
#*)
# Command1
#    ;;
#esac
#示例如下:

1 Echo 'Input A number between 1 to 4'2 Echo-E'Your number is:\c'3 Read Anum4  Case$aNuminch5         1)Echo 'You select 1'6         ;;7         2)Echo 'You select 2'8         ;;9         3)Echo 'You select 3'Ten         ;; One         4)Echo 'You Select 4' A         ;; -*)Echo 'You does not select a number between 1 to 4' -         ;; the Esac

#测试输入xxx. sh-f index.html or xxx.sh-d Unix enters x at this point) output

1option="${1}"2  Case${option}inch3-f) file="${2}"4       Echo "File name is $FILE"5       ;;6-D) dir="${2}"7       Echo "Dir name is $DIR"8       ;;9*) Ten       Echo "' basename ${0} ': Usage: [-f file] | [-D directory]"#如果都不是, the xxx is executed.SH# OneExit1# Command to come out of the program with status1 A       ;; - Esac

Linux Gvim Shell CASE...ESAC statement

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.