执行  ./test.sh -d www.baidu.com -n yyy

test.sh文件

#!/bin/bash

DOMAIN=""
NAME=""

while getopts ":d:n:" OPTION
do
  case $OPTION in
    d)
      echo "选项-d的参数值是:$OPTARG"
      DOMAIN=$OPTARG
      ;;
    n)
      echo "选项-n的参数值是:$OPTARG"
      NAME=$OPTARG
      ;;

  esac
done


echo "接收域名为:$DOMAIN"
echo "接收名称为: $NAME"
if [ -z  "$NAME" ]
then
   echo "名称不能为空"
   exit 1
else
   echo "名称不为空~"
fi