#!/bin/bash
parse_arguments() {
while getopts ":s:n:i:d:p:" opt; do
case $opt in
n) n=$OPTARG;;
s) s=$OPTARG;;
d) d=$OPTARG;;
i) i=$OPTARG;;
p) p=$OPTARG;;
:) echo "选项-$OPTARG后面需要一个参数值"; exit 1 ;;
?) echo "无效的选项 -$OPTARG"; exit 2 ;;
esac
done
}
parse_arguments "$@"
echo "选项n的值是$n"
echo "选项s的值是$s"
echo "选项d的值是$d"
echo "选项i的值是$i"
echo "选项p的值是$p"
./c.sh -n ad -s ss -p d -iasd -d "dddd sdfgsg"
标签:脚本,选项,指定,echo,parse,参数,arguments,opt,OPTARG
From: https://www.cnblogs.com/outsrkem/p/17342093.html