怎么在Shell脚本中通过参数名传递参数

这期内容当中小编将会给大家带来有关怎么在Shell脚本中通过参数名传递参数,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

#!/bin/bash
while getopts i:o:p:s:t: OPT; do
 case ${OPT} in
  i) in_file=${OPTARG}
    ;;
  o) out_dir=${OPTARG}
    ;;
  p) product_code=${OPTARG}
    ;;
  s) software_version=${OPTARG}
    ;;
  t) type=${OPTARG}
    ;;
  \?)
    printf "[Usage] `date '+%F %T'` -i <INPUT_FILE> -o <OUTPUT_DIR> -o <P
RODUCT_CODE> -s <SOFTWARE_VERSION> -t <TYPE>\n" >&2
    exit 1
 esac
done
 
# check parameter
if [ -z "${in_file}" -o -z "${out_dir}" -o -z "${product_code}" -o -z "${software_version}" -o -z "${type}" ]; then
  printf "[ERROR] `date '+%F %T'` following parameters is empty:\n-i=${in_file}\n-o=${out_dir}\n-p=${product_code}\n-s=${software_version}\n-t=${type}\n"
  exit 1
fi
 
# block enc
java -jar openailab-command-line-auth-0.1-SNAPSHOT.jar ${in_file} ${out_dir} ${product_code} ${software_version} ${type}

上述就是小编为大家分享的怎么在Shell脚本中通过参数名传递参数了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。