首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Shell施用getopts读取参数

2012-10-25 
Shell使用getopts读取参数使用getopts可以处理command [-i infile] outfile。不过还不知道怎么处理像com

Shell使用getopts读取参数

使用getopts可以处理

<command> [-i infile] outfile。不过还不知道怎么处理像<command> outfile [-i infile]。因为getopts遇到outfile时就会放弃分析。

usage='Usage: <command> [-i infile] outfile'infile='/tmp/infile'while getopts ":i:" opt; do    case $opt in        i)            infile=$OPTARG            ;;        ?)            echo $usage >&2            exit 1;            ;;        :)            echo "OPtion -$OPTARG requires an argument." >&2            exit 1;            ;;    esacdoneshift `expr $OPTIND - 1`outfile=$1
?

热点排行