Azure CLI with Bash Variables - Part 2

Length: 00:13:49

Lesson Summary:

Continuing from part 1, we expand our knowledge of variables by considering array variables.

Array variables allow us to contain multiple pieces of related information within a single multi-dimensional variable.

This lesson goes on to make use of the concepts we've learned, by creating resources using both Azure CLI and array variables.

Important commands used in this lesson:

  • Creating an indexed array: indexedA=("value one" value2 "some words")
  • Creating an associative array: declare -A associativeArray
  • Assigning a value to our associative array: associativeArray[value1]="value one"
  • Echoing the first value in the indexed array: echo ${indexedA[0]}
  • Echoing the value from an array with the index value1: ${associativeArray[value1]}

Use the following commands to create resources:

  • declare -A book1
  • book1[name]="hammeroftruth"
  • book1[rgname]="hammeroftruth-rg"
  • book1[saname]="hammeroftruthstore"
  • book1[vnetname]="hammeroftruth-vnet"
  • book1[location]="australiasoutheast"
  • az group create -n ${book1[rgname]} -l ${book1[location]}
  • az network vnet create -g ${book1[rgname]} -n ${book1[vnetname]} --address-prefix 10.2.0.0/16
  • az storage account create -g ${book1[rgname]} -n ${book1[saname]}

All commands used in this lesson if you wish to follow along:

indexedA=("value one" value2 "some words")

declare -A associativeArray
associativeArray[value1]="value one"

echo ${indexedA[0]}
echo ${indexedA[1]}
echo ${indexedA[2]}
echo $indexedA[2]

echo ${associativeArray[value1]}

declare -A book1
book1[name]="hammeroftruth"
book1[rgname]="hammeroftruth-rg"
book1[saname]="hammeroftruthstore"
book1[vnetname]="hammeroftruth-vnet"
book1[location]="australiasoutheast"

echo ${book1[saname]}

az group create -n ${book1[rgname]} -l ${book1[location]}
az network vnet create -g ${book1[rgname]} -n ${book1[vnetname]} --address-prefix 10.2.0.0/16  
az storage account create -g ${book1[rgname]} -n ${book1[saname]}

This lesson is only available to Linux Academy members.

Sign Up To View This Lesson

Or Log In

Looking For Team Training?

Learn More