我有以下 bash 腳本:
#!/bin/bash
function usage() {
printf "\n"
echo "Updates a Lambda with env vars stored in a Secrets Manager secret. Complete drop n' swap."
printf "\n"
echo "Syntax: bash $0 -a <ARN> -s <secretName> [-h]"
echo "options:"
echo "a the ARN of the Lambda to update"
echo "s the name of the secret in Secrets Manager to use"
echo "h display help"
printf "\n"
exit
}
while getopts ":has:" option; do
case $option in
h) # display help
usage
;;
a) # ARN of the lambda
arn=${OPTARG}
[[ -z "$arn" ]] && usage
;;
s) # Secrets Manager secret (name)
secretName=${OPTARG}
[[ -z "$secretName" ]] && usage
;;
*) # catchall
usage
esac
done
echo "all good! arn = $arn and secret = $secretName"
當我運行它時,我得到:
myuser@mymachine myapp % bash myscript.sh -a abba -s babba
Updates a Lambda with env vars stored in a Secrets Manager secret. Complete drop n' swap.
Syntax: bash myscript.sh -a <ARN> -s <secretName> [-h]
options:
a the ARN of the Lambda to update
s the name of the secret in Secrets Manager to use
h display help
我期望所有引數(由 決議getopts)都是有效的,并且可以看到"all good!..."輸出而不是使用輸出。
我哪里出錯了?我是在錯誤地使用/決議getopts,還是錯誤地使用引數呼叫腳本?或兩者?!提前致謝!
uj5u.com熱心網友回復:
由于-a應該有一個關聯的值,因此您希望將 a 附加:到a選項中,即:
# change this:
while getopts ":has:" option
# to this:
while getopts ":ha:s:" option
^--------------
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/520093.html
標籤:重击获取选择
