shell传参

#!/bin/bash

zendkey=/root/license.key

while getopts :p:e:s:d: OPTION

  do 
  
    case $OPTION in 
    
      p) product="$OPTARG" ;;
      
      e) expire="$OPTARG" ;;
      
      s) souraddress="$OPTARG" ;;
      
      d) destaddress="$OPTARG" ;;
      
      ?|h) echo -e "Please input the following parameters\n-p:product-name\n-e:Effective date ,it must be this format: yyyy-mm-dd\n-s:Source directory\n-d:Target directory " ; exit 1;;
      
    esac    
    
  done
  
    if [ -z "${product}" -o -z "${expire}" -o -z "${souraddress}" -o -z "${destaddress}" ]
    
    then
    
        echo "-p -e -s -d Parameters are required, and default values cannot be used." && exit 1
        
    fi
    ```

猜你喜欢

转载自blog.csdn.net/Alice66666/article/details/83055049