shell case esac语句

来源:互联网 发布:linux下echo命令详解 编辑:程序博客网 时间:2024/05/08 09:39
shell脚本如下代码echo 'Input a number between 1 to 4'echo 'Your number is:\c'read aNumcase $aNum in    1)  echo 'You select 1'    ;;    2)  echo 'You select 2'    ;;    3)  echo 'You select 3'    ;;    4)  echo 'You select 4'    ;;    *)  echo 'You do not select a number between 1 to 4'    ;;esac输出结果Input a number between 1 to 4Your number is:3You select 3再举例#!/bin/bashoption="${1}"case ${option} in   -f) FILE="${2}"      echo "File name is $FILE"      ;;   -d) DIR="${2}"      echo "Dir name is $DIR"      ;;   *)       echo "`basename ${0}`:usage: [-f file] | [-d directory]"      exit 1 # Command to come out of the program with status 1      ;;esac$./test.shtest.sh: usage: [ -f filename ] | [ -d directory ]$ ./test.sh -f index.htm$ vi test.sh$ ./test.sh -f index.htmFile name is index.htm$ ./test.sh -d unixDir name is unix$



0 0
原创粉丝点击