#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