How to read an individual items of an array in bash for loop
by sysmicuser from LinuxQuestions.org on (#5K3D9)
Hi Guys,
I have a code snippet below
Code:values=(addressSearchBaseUrl addressSearchSubscriptionKey cacheUrl calendarApiUrl checkoutBffApiUrl cpCode)
az_create_options=()
for ptr in "${values[@]}"
do
result=$(
az pipelines variable-group list --group-name "${Variable Group ${reference_env}" | jq '.[0].variables.'${ptr}'.value'
)
if [[ "$ptr" = "calendarApiUrl" ]]
then
echo "INF: Updating $ptr with new value"
result="https://noname-api.platform.test.com.au/marketing/calendar/v1/AvailableDates/market1/"
insertString=";rev=${target_env}"
lookingfor="v1"
result=$(echo $result| sed s/"${lookingfor}"/"${insertString}"/g)
echo $result
fi
az_create_options+=("$result" )
done
declare -p az_create_options
values=(addressSearchBaseUrl addressSearchSubscriptionKey cacheUrl calendarApiUrl checkoutBffApiUrl cpCode)
for ptr in "${values[@]}"
do
az pipelines variable-group variable update --group-id 1543 --name "${ptr} --value "${az_create_options[0]}" First element read and value updated
az pipelines variable-group variable update --group-id 1543 --name "${ptr} --value "${az_create_options[0]}" Second element read and value updated
done
The last for loop is where I need help as I do not know how to refer an array in bash.I need to point to individual items of az_create_options as they have to go 1:1.
Forgive me for my bash incompetency, but, I am here to learn.
I have a code snippet below
Code:values=(addressSearchBaseUrl addressSearchSubscriptionKey cacheUrl calendarApiUrl checkoutBffApiUrl cpCode)
az_create_options=()
for ptr in "${values[@]}"
do
result=$(
az pipelines variable-group list --group-name "${Variable Group ${reference_env}" | jq '.[0].variables.'${ptr}'.value'
)
if [[ "$ptr" = "calendarApiUrl" ]]
then
echo "INF: Updating $ptr with new value"
result="https://noname-api.platform.test.com.au/marketing/calendar/v1/AvailableDates/market1/"
insertString=";rev=${target_env}"
lookingfor="v1"
result=$(echo $result| sed s/"${lookingfor}"/"${insertString}"/g)
echo $result
fi
az_create_options+=("$result" )
done
declare -p az_create_options
values=(addressSearchBaseUrl addressSearchSubscriptionKey cacheUrl calendarApiUrl checkoutBffApiUrl cpCode)
for ptr in "${values[@]}"
do
az pipelines variable-group variable update --group-id 1543 --name "${ptr} --value "${az_create_options[0]}" First element read and value updated
az pipelines variable-group variable update --group-id 1543 --name "${ptr} --value "${az_create_options[0]}" Second element read and value updated
done
The last for loop is where I need help as I do not know how to refer an array in bash.I need to point to individual items of az_create_options as they have to go 1:1.
Forgive me for my bash incompetency, but, I am here to learn.