Sample Header Ad - 728x90

Azure CLI bash loop not working

1 vote
1 answer
528 views
I'm trying to learn bash and become less PowerShell dependent but running into issues with what seems like an easy loop. Below is my attempt to get the loop to return each VM result with it's associated name, id, and tag. Any help is much appreciated.
#Get a list of VMs with their name, id, and tags from Azure 
r=$(az vm list -g lab.rg1 --query "[].{name:name, id:id, tags:tags}") #--output tsv)

#take that list and do something. Currently just trying to echo each VM with it's name,id, and tags.
while read r
do
    echo $r
done

echo All Done
Asked by Braden (11 rep)
Feb 22, 2024, 05:53 PM
Last activity: Feb 22, 2024, 05:57 PM