shell脚本里读取命令行参数

来源:互联网 发布:mac上用什么输入法 编辑:程序博客网 时间:2024/06/02 06:08
#!/bin/bash
usage_msg="USAGE:`basename $0` -h <hadoop 1 namenode ip> -t <table>"
 if [[ $# -ne 4 ]];then  
     echo $usage_msg 
     exit 1  
 fi 
 
 while getopts h:t: opt; do 
   case $opt in
       h) 
         namenode=$OPTARG
       ;;
       t) 
         tablename=$OPTARG

       ;;

#如果参数不对,程序退出

  \?) echo $usage_msg
           exit  1
           ;;
   esac

done 

#判断参数是否正确赋值

if [ -z $tablename ] ; then
          echo   "option -t not specified"
          echo "$OPTIND"
fi
echo "####copy table:$tablename####";



0 0