shell case esac语句
2017-02-08 11:50
302 查看
shell脚本如下代码 echo 'Input a number between 1 to 4' echo 'Your number is:\c' read aNum case $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 4 Your number is:3 You select 3 再举例 #!/bin/bash option="${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.sh test.sh: usage: [ -f filename ] | [ -d directory ] $ ./test.sh -f index.htm $ vi test.sh $ ./test.sh -f index.htm File name is index.htm $ ./test.sh -d unix Dir name is unix $
相关文章推荐
- Shell case esac语句
- Shell case esac语句
- Shell case esac语句
- Shell case esac语句
- 【Shell脚本学习17】Shell case esac语句
- Shell case esac语句
- (11)shell case esac语句
- 30分钟玩转Shell-Shell case esac语句
- 十五、Shell case esac语句
- Shell case esac语句
- Shell case esac语句【转】
- Shell case esac语句
- Shell case esac语句
- Shell case esac语句
- Shell case esac语句
- Shell case esac语句
- shell流程控制语句 case
- linux-shell中case与select语句
- shell学习二十二--case语句
- Shell Scripts - 条件语句,case语句,function功能