I am a newbie for the bash shell. The previous developer created the following codes to use a shell script to deploy AWS cloudformation stack.
jq
to convert it to an array called parameters
${parameters[@]}
to spread into key=value pair stringsThe problem is one array value is cron(0 20-6 * *? *)
. The deploy.sh will convert the *
as current directory file names such as cron(0 20-6 CODEOWNERS README.md CODEOWNERS README.md? *)
My question: How can I let my deploy.sh to escape the *
characters when calling ${parameters[@]}
.
Here are the example codes:
dev.json
{
"Parameters": {
"Environment": "dev",
"CrawlerScheduleExpression": "cron(0 20-6 * * ? *)"
},
"Tags": {
"Severity": "High",
"Environment": "dev",
"DeletionPolicy": "Retain"
}
}
deploy.sh
parameters=($(jq -r '.Parameters | keys[] as $k | "\($k)=\(.[$k])"' "dev.json"))
tags=($(jq -r '.Tags | keys[] as $k | "\($k)=\(.[$k])"' "${conf_file}"))
aws cloudformation deploy \
--s3-bucket ${BUILD_ARTIFACTS_BUCKET} \
--s3-prefix ${PROJECT_NAME} \
--template-file ${template} --stack-name ${STACK_NAME} \
--parameter-overrides "${parameters[@]}" \ # Environment=dev CrawlerScheduleExpression=cron(0 20-6 CODEOWNERS README.md CODEOWNERS README.md ? *)
--tags "${tags[@]}"
In the end, I have to disable the bash wildcard expansion to achieve my goal:(
set noglob on
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.