如何获取shell脚本的可选参数

来源:互联网 发布:网络成瘾的症状 编辑:程序博客网 时间:2024/06/05 22:32

直接上例子:

cat option_sh #!/bin/bashecho $*# get the optional argumentswhile getopts f:t: valuedo    case $value in        f )            RHOST_INFO=$OPTARG   # 从$OPTARG中获得参数值            ;;        t )            TIMEOUT=$OPTARG            ;;    esacdoneecho $@shift $(($OPTIND-1))      # 偏移至后面的参数echo $*echo $1if [ $TIMEOUT == "30" ]   # 获得的参数为字符串thenecho here fingnlinux1 [** NONE **]/home/qius $ ngnlinux1 [** NONE **]/home/qius $ ./option_sh -t 30 -f ss  other paras-t 30 -f ss other paras-t 30 -f ss other paras
other paras
other
here
使用方法:example.sh -f file_name -t timeoutvalue  other paras

原创粉丝点击