Skip to content

Commit c7acdb9

Browse files
authored
Merge pull request #193613 from baanders/3-31-shell
ADT: Info for CLI special chars
2 parents debf618 + 1dfb8fe commit c7acdb9

File tree

5 files changed

+119
-5
lines changed

5 files changed

+119
-5
lines changed

articles/digital-twins/TOC.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@
154154
- name: Error 404 (Sub-Domain not found)
155155
href: troubleshoot-error-404.md
156156
- name: Azure Digital Twins Explorer authentication error
157-
href: troubleshoot-error-azure-digital-twins-explorer-authentication.md
157+
href: troubleshoot-error-azure-digital-twins-explorer-authentication.md
158+
- name: CLI parsing failures
159+
href: troubleshoot-error-cli-parse.md
158160
- name: Reference
159161
items:
160162
- name: REST API reference

articles/digital-twins/concepts-cli.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ titleSuffix: Azure Digital Twins
55
description: Learn about the Azure Digital Twins CLI command set.
66
author: baanders
77
ms.author: baanders # Microsoft employees only
8-
ms.date: 02/28/2022
8+
ms.date: 03/31/2022
99
ms.topic: conceptual
1010
ms.service: digital-twins
1111

@@ -17,7 +17,7 @@ ms.service: digital-twins
1717

1818
# Azure Digital Twins CLI command set
1919

20-
Apart from managing your Azure Digital Twins instance in the Azure portal, Azure Digital Twins also has a command set for the [Azure CLI](/cli/azure/what-is-azure-cli) that you can use to do most major actions with the service. This article covers the [Azure CLI](/cli/azure/what-is-azure-cli) in terms of its uses, how to get it, and the requirements for using it.
20+
Apart from managing your Azure Digital Twins instance in the Azure portal, Azure Digital Twins also has a command set for the [Azure CLI](/cli/azure/what-is-azure-cli) that you can use to do most major actions with the service. This article covers the Azure CLI command set for Azure Digital twins including its uses, how to get it, and the requirements for using it.
2121

2222
Some of the actions you can do using the command set include:
2323
* Managing an Azure Digital Twins instance
@@ -61,6 +61,67 @@ Otherwise, you can use the following command to install the extension yourself a
6161
az extension add --upgrade --name azure-iot
6262
```
6363

64+
## Use special characters in different shells
65+
66+
Some `az dt` commands use special characters that may have to be escaped for proper parsing in certain shell environments. Use the tips in this section to help you know when to do this in your shell of choice.
67+
68+
### Bash
69+
70+
Use these special character tips for Bash environments.
71+
72+
#### Queries
73+
74+
In many twin queries, the `$` character is used to reference the `$dtId` property of a twin. When using the [az dt twin query](/cli/azure/dt/twin#az-dt-twin-query) command to query in the Cloud Shell Bash environment, escape the `$` character with a backslash (`\`).
75+
76+
Here is an example of querying for a twin with a CLI command in the Cloud Shell Bash environment:
77+
78+
```azurecli
79+
az dt twin query -n <instance-name> -q "SELECT * FROM DigitalTwins T Where T.\$dtId = 'room0'"
80+
```
81+
82+
### PowerShell
83+
84+
Use these special character tips for PowerShell environments.
85+
86+
#### Inline JSON
87+
88+
Some commands, like [az dt twin create](/cli/azure/dt/twin#az-dt-twin-create), allow you to enter twin information in the form of inline JSON. When entering inline JSON in the PowerShell environment, escape double quote characters (`"`) inside the JSON with a backslash (`\`).
89+
90+
Here is an example of creating a twin with a CLI command in PowerShell:
91+
92+
```azurecli
93+
az dt twin create --dt-name <instance-name> --dtmi "dtmi:contosocom:DigitalTwins:Thermostat;1" --twin-id thermostat67 --properties '{\"Temperature\": 0.0}'
94+
```
95+
96+
>[!TIP]
97+
>Many of the commands that support inline JSON also support input as a file path, which can help you avoid shell-specific text requirements.
98+
99+
#### Queries
100+
101+
In many twin queries, the `$` character is used to reference the `$dtId` property of a twin. When using the [az dt twin query](/cli/azure/dt/twin#az-dt-twin-query) command to query in a PowerShell environment, escape the `$` character with a backtick character.
102+
103+
Here is an example of querying for a twin with a CLI command in PowerShell:
104+
```azurecli
105+
az dt twin query -n <instance-name> -q "SELECT * FROM DigitalTwins T Where T.`$dtId = 'room0'"
106+
```
107+
108+
### Windows CMD
109+
110+
Use these special character tips for the local Windows CMD.
111+
112+
#### Inline JSON
113+
114+
Some commands, like [az dt twin create](/cli/azure/dt/twin#az-dt-twin-create), allow you to enter twin information in the form of inline JSON. When entering inline JSON in a local Windows CMD window, enclose the parameter value with double quotes (`"`) instead of single quotes (`'`), and escape double quote characters inside the JSON with a backslash (`\`).
115+
116+
Here is an example of creating a twin with a CLI command in the local Windows CMD:
117+
118+
```azurecli
119+
az dt twin create --dt-name <instance-name> --dtmi "dtmi:contosocom:DigitalTwins:Thermostat;1" --twin-id thermostat67 --properties "{\"Temperature\": 0.0}"
120+
```
121+
122+
>[!TIP]
123+
>Many of the commands that support inline JSON also support input as a file path, which can help you avoid shell-specific text requirements.
124+
64125
## Next steps
65126

66127
Explore the CLI and its full set of commands through the reference docs:

articles/digital-twins/how-to-ingest-iot-hub-data.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,14 @@ To create a thermostat-type twin, you'll first need to upload the thermostat [mo
5757
You'll then need to create one twin using this model. Use the following command to create a thermostat twin named thermostat67, and set 0.0 as an initial temperature value.
5858

5959
```azurecli-interactive
60-
az dt twin create --dt-name <instance-name> --dtmi "dtmi:contosocom:DigitalTwins:Thermostat;1" --twin-id thermostat67 --properties '{"Temperature": 0.0,}'
60+
az dt twin create --dt-name <instance-name> --dtmi "dtmi:contosocom:DigitalTwins:Thermostat;1" --twin-id thermostat67 --properties '{"Temperature": 0.0}'
6161
```
6262

63+
>[!NOTE]
64+
>If you're using anything other than Cloud Shell in the Bash environment, you may need to escape certain characters in the inline JSON so that it's parsed correctly.
65+
>
66+
>For more information, see [Use special characters in different shells](concepts-cli.md#use-special-characters-in-different-shells).
67+
6368
When the twin is created successfully, the CLI output from the command should look something like this:
6469
```json
6570
{
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: "Troubleshoot CLI parsing failures"
3+
titleSuffix: Azure Digital Twins
4+
description: Learn how to diagnose and resolve parsing failures with the Azure Digital Twins CLI command set.
5+
ms.service: digital-twins
6+
author: baanders
7+
ms.author: baanders
8+
ms.topic: troubleshooting
9+
ms.date: 03/31/2022
10+
---
11+
12+
# Troubleshoot parsing failures with Azure Digital Twins CLI commands
13+
14+
This article describes causes and resolution steps for various "parse failed" errors while running [az dt](/cli/azure/dt) commands in the Azure CLI.
15+
16+
## Symptoms
17+
18+
While attempting to run select `az dt` commands in an Azure CLI environment, you receive an error indicating that the command wasn't parsed correctly. The error message might include the words *parse failed* or *failed to parse*, or partial text from your command may be marked as *unrecognized arguments.*
19+
20+
## Causes
21+
22+
### Cause #1
23+
24+
Some `az dt` commands use special characters that have to be escaped for proper parsing in certain shell environments. It is possible that some special character in your CLI command needs to be escaped for it to be parsed in the shell that you're using.
25+
26+
## Solutions
27+
28+
### Solution #1
29+
30+
Use the full error message text to help you determine which character is causing an issue. Then, try escaping instances of this character with a backslash or a backtick. For a list of some specific characters that need to be escaped in certain shells, see [Use special characters in different shells](concepts-cli.md#use-special-characters-in-different-shells).
31+
32+
### Solution #2
33+
34+
If you're encountering the parsing issue while passing inline JSON into a command (like [az dt model create](/cli/azure/dt/model#az-dt-model-create) or [az dt twin create](/cli/azure/dt/twin#az-dt-twin-create)), check whether the command allows you to pass in a file instead. Many of the commands that support inline JSON also support input as a file path, which can help you avoid shell-specific text requirements.
35+
36+
### Solution #3
37+
38+
Not all shells have the same special character requirements, so you can try running the command in a different shell type (some options are the [Cloud Shell](https://shell.azure.com) Bash environment, [Cloud Shell](https://shell.azure.com) PowerShell environment, local Windows CMD, local Bash window, or local PowerShell window).
39+
40+
## Next steps
41+
42+
Read more about the CLI for Azure Digital Twins:
43+
* [Azure Digital Twins CLI command set](concepts-cli.md)
44+
* [az dt command reference](/cli/azure/dt)

articles/digital-twins/tutorial-command-line-cli.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ To create a digital twin, you use the [az dt twin create](/cli/azure/dt/twin#az-
143143
```
144144
145145
>[!NOTE]
146-
> It's recommended to use the CLI in the Bash environment for this tutorial. If you're using the PowerShell environment, you may need to escape the quotation mark characters in order for the `--properties` JSON value to be parsed correctly.
146+
>If you're using anything other than Cloud Shell in the Bash environment, you may need to escape certain characters in the inline JSON so that it's parsed correctly.
147+
>
148+
>For more information, see [Use special characters in different shells](concepts-cli.md#use-special-characters-in-different-shells).
147149
148150
The output from each command will show information about the successfully created twin (including properties for the room twins that were initialized with them).
149151

0 commit comments

Comments
 (0)