How do you type a multi-line command on Azure Interactive Shell?

Austin Lee 11 Reputation points
2022-12-09T13:44:18.387+00:00

I am working in the sandbox on Microsoft Azure training. I cannot figure out how to enter a multi-line command in the Azure Interactive Shell. I believe entering the backslash '\' should start a new line, but that does not work. Here is the command I am trying to enter:
az network nsg rule create \
--resource-group learn-78daa456-3316-43d7-9a60-f3ec613dca9f \
--nsg-name my-vmNSG \
--name allow-http \
--protocol tcp \
--priority 100 \
--destination-port-range 80 \
--access Allow

Azure | Azure Training
{count} votes

2 answers

Sort by: Most helpful
  1. Hoekstra Jelle 501 Reputation points
    2022-12-09T15:39:28.863+00:00

    Hi,

    I just verified the command..
    The command works.
    Enter 1 line at a time, and make sure you see > at the start of the 2nd line all the way up to the end.

    So do it like:
    az network nsg rule create \

    Shift+Enter

    --resource-group learn-78daa456-3316-43d7-9a60-f3ec613dca9f \

    Shift+Enter

    etc and in the end give an enter.. It will work!

    Hope this helps

    ----------

    If this solved the issue, please accept the answer and upvote!


  2. kobulloc-MSFT 26,811 Reputation points Microsoft Employee Moderator
    2022-12-09T18:33:12.783+00:00

    Hello, @Austin Lee !

    Where am I seeing this?

    How do I type multi-line commands in the sandbox/interactive Azure Cloud Shell?
    When entering multi-line commands, you'll use "\" for Bash and "`" for PowerShell. Since the sandbox defaults to Bash, you use "\". This allows you to enter lines one at a time without executing them or paste entire blocks all at once.

    When using the sandbox, you'll want to right click and select paste rather than using keyboard shortcuts as that can create characters that will invalidate the multi-line formatting (see screenshot below).

    If you are using "\" and are running into issues, please share a screenshot and I'd be happy to help you troubleshoot this. I'll follow up with you directly.

    Entering a multi-line command successfully in the sandbox

    269021-image.png

    Pasting a multi-line command line by line (right click, paste, then press Enter)

    269031-image.png

    Watch out for keyboard shortcuts (Ctrl + C) adding invalid characters

    269012-image.png

    Using the Azure Cloud Shell

    Documentation examples will sometimes use multi-line characters that are specific to one shell even if the commands themselves can be run in both PowerShell and Bash. Be sure to use the correct multi-line characters in the correct shell.

    Multi-line command in Bash

    269005-image.png

    Multi-line command in PowerShell

    269006-image.png

    Errors when using the wrong multi-line character in the wrong shell

    268940-image.png

    0 comments No comments

Your answer

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