我有一个如下的for循环,
values="addressSearchBaseUrl addressSearchSubscriptionKey cacheUrl calendarApiUrl checkoutBffApiUrl cpCode"
for ptr in $values
do
echo $ptr
temp=$(az pipelines variable-group list --group-name "${target_backend}"|jq '.[0].variables.'${ptr}'.value')
echo $temp
echo $?
done
现在,我希望在下面的命令中引用每个结果:
az pipelines variable-group variable create true --name "Sales.Configuration.Spa ${new_env}" --variable "addressSearchBaseUrl" --value "${parse or store the value from above loop}" "addressSearchSubscriptionKey" "--value "${parse or store the value from above loop}"...
有人能帮帮我吗?
添加一些换行符确实有助于提高代码的可读性。
利用外壳阵列:
values=(
addressSearchBaseUrl
addressSearchSubscriptionKey
cacheUrl
calendarApiUrl
checkoutBffApiUrl
cpCode
)
az_create_options=()
for ptr in "${values[@]}"
do
result=$(
az pipelines variable-group list --group-name "${target_backend}"
| jq ".[0].variables.${ptr}.value"
)
printf "%st%st%dn" "$ptr" "$result" $?
# add the variable and value to the array
az_create_options+=( --variable "$ptr" --value "$result" )
done
# inspect the create options, if you want
declare -p az_create_options
# now, create them
az pipelines variable-group variable create true
--name "Sales.Configuration.Spa ${new_env}"
"${az_create_options[@]}"