How To Use Variables with Azure CLI

In this blog post, we’ll explore how to use variables with Azure CLI, step-by-step. We’ll cover how to declare variables, and how to use them in Azure CLI commands

When working with Azure CLI, you may encounter scenarios where you need to use variables to store and reuse values such as resource group names, storage account names, or subscription IDs.

Declare Variable

To get started, we start by declaring a variable using the following command.

Declare a variable using the following syntax.


For Example


Use the variable in Azure CLI commands by enclosing the variable name in curly braces, preceded by a dollar sign. For example, to create a virtual machine with the resource group name stored in the RESOURCE_GROUP variable, you can use the following command:

az vm create --resource-group ${RESOURCE_GROUP} --name myVM --image UbuntuLTS

You can also use variables in combination with other shell commands, such as if statements and loops. For example:

if [[ $RESOURCE_GROUP == "myresourcegroup" ]]; then
az group delete --name ${RESOURCE_GROUP} --yes

Note that variables are case-sensitive, so make sure to use the same capitalization throughout your commands. Also, be careful not to include spaces around the equals sign when declaring a variable

Visit Jooble Company to find the best opportunities for developers

Success! You're on the list.





Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.