Reputation: 819
I am trying to use variable in azure CLI like we used in powershell.
In powershell we define variable as follows
$LOCATION = value
And used it in command as follows
az group create --name foo --location $LOCATION
What I have tried :-
I have tried to find it out in Microsoft documentation
https://learn.microsoft.com/en-us/cli/azure/get-started-with-azure-cli?view=azure-cli-latest
but I did not get any information about that.
Question :-
Note:- I have installed azure CLI at my local.
Upvotes: 12
Views: 25713
Reputation: 13749
Assignment: use double quotes if you are assigning a long string (export
is not needed):
AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=MYACCNAME;AccountKey=MYACCKEY"
Usage: invoke/surround it with ${}
, example:
checking Storage Queue messages:
az storage message peek \
--connection-string ${AZURE_STORAGE_CONNECTION_STRING} \
--queue-name MYQUEUE
printing:
echo ${AZURE_STORAGE_CONNECTION_STRING}
Upvotes: 0
Reputation: 8132
The easiest way to pass variables
to any CLI command is by using environment variables
An environment variable is a variable whose value is set outside the program, typically through a functionality built into the operating system or microservice. An environment variable is made up of a name/value pair, and any number may be created and available for reference at a point in time.
Below you can find examples in Bash and CMD:
Bash-
Set new environment variable-
export LOCATION=westeurope
Print the environment variable-
echo ${LOCATION}
AZ CLI example-
az group create --name foo --location ${LOCATION}
CMD-
Set new environment variable-
set LOCATION=westeurope
Print the environment variable-
echo %LOCATION%
AZ CLI example-
az group create --name foo --location %LOCATION%
Upvotes: 11
Reputation: 65431
You could do it like this:
New-Variable -Name "location" -Visibility Public -Value "eastus"
Upvotes: 0
Reputation: 222682
It is the same way you do it in powershell,
To assign a value
sajeetharan@Azure:~$ LOCATION="eastus"
To check value is set,
sajeetharan@Azure:~$ echo $LOCATION
eastus
Upvotes: 1