A basic question about using the Azure CLI interface

Charlie Melga 126 Reputation points
2023-07-18T10:06:03.3033333+00:00

Hello

I started reading a book entitled 'Azure Cookbook' and through out the book is uses the Azure CLI (rather than PowerShell which I am used to).

If I follow the syntax as written in the book (or rather as I understand it to be written) I am getting errors. Therefore I think I must be misinterpreting what is meant here is one example

The book states type the following command

subscriptionId=$(az account show \
  --query "id" --output tsv)
subscriptionScope="/subscriptions/"$subscriptionId

However, if I do that (either a the cmd.exe prompt or within 'az interactive' shell on my Windows 10 machine)

I receive the following error

'subscriptionID=$(az' is misspelled or not recognized by the system

Therefore I tried again but this time I added a $ to the front for example

$subscriptionId=$(az account show \

  --query "id" --output tsv)

subscriptionScope="/subscriptions/"$subscriptionId


This time a message was returned that stated

Success: 0

Questions

Can someone kindly advise where I am going wrong as there are hundreds of examples in the book of similar code syntax. So I need to know what I am doing wrong/what I need to change in order I can work through the other examples in the book correctly

  1. To me, a 0 (zero) normally means fail ?
  2. Also, does the \ (backslash) character represent an escape character (new line in this case) in Azure CLI language ?

Thanks in advance
CXMelga

Community Center | Not monitored
0 comments No comments
{count} votes

Answer accepted by question author
  1. TP 145.5K Reputation points Volunteer Moderator
    2023-07-18T12:51:32.35+00:00

    Hi Charlie,

    Please try the book examples with Bash. More details below.

    I'm assuming you are referring to Azure Cookbook by Reza Salehi. Please correct me if my assumption is wrong. Early in the book under "What You Will Need" it says Terminal with Bash or Z shell (Zsh).

    Azure CLI can be used within multiple different shell environments, however, depending on which you are using it you will need to modify some of your syntax to fit the specific environment. In general, Azure CLI is more suited to those familiar with Bash.

    Which Azure command-line tool is right for you?

    https://learn.microsoft.com/en-us/cli/azure/choose-the-right-azure-command-line-tool#which-azure-command-line-tool-is-right-for-you

    You can use Bash under Windows. For example, you can use Git Bash app, or via Windows Subsystem for LInux, or other ways:

    Install Linux on Windows with WSL

    https://learn.microsoft.com/en-us/windows/wsl/install

    You can also use Bash via Azure Cloud Shell in the Azure portal.

    Please click Accept Answer if the above is useful.

    Thanks.

    -TP


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.