셸 스크립트로 매개 변수를 분석하는 템플릿
무엇으로
있음
getopts
, 그러나 긴 옵션을 사용하고 높은 기능getopt
을 사용합니다.GNU 버전과 BSD 버전의 규격은 차이가 있지만 GNU 버전을 따른다.
거푸집
_usage() {
echo "usage"
echo " -a | --arg <str>"
echo " -h | --help Show this message and exit"
}
ARGUMENT="${@}"
option_short="a:dh"
option_long="arg:,debug,help"
OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- ${ARGUMENT})
[[ ${?} != 0 ]] && exit 1
unset option_short option_long
eval set -- "${OPT}"
while :; do
case ${1} in
-a | --arg)
arg="${2}"
shift 2
;;
-h | --help)
_usage
shift 1
exit 0
;;
--)
shift
break
;;
*)
echo "Unknows options ${1}" >&2
exit 1
;;
esac
done
Reference
이 문제에 관하여(셸 스크립트로 매개 변수를 분석하는 템플릿), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/hayao/articles/bcb38fbd6d6dab텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)