【问题标题】:How do I insert special characters in to Azure table storage with "az storage entity insert"-command?如何使用“az storage entity insert”命令将特殊字符插入 Azure 表存储?
【发布时间】:2021-10-16 19:13:34
【问题描述】:

我有一个动态构建“az storage entity insert”命令的 Powershell 脚本。基本上,我有一个 CSV 文件,我用它来创建表的内容,方法是将其转换为然后调用的长命令。在我添加一个包含正则表达式的字段之前,它一直运行良好。

我开始感到奇怪“系统找不到指定的路径。”错误。不是像您首先怀疑的那样访问 CSV,而是运行生成的命令。我发现字段值中的一些特殊字符会破坏命令,并且它会尝试执行之后的内容作为一些单独的命令或其他内容。

我简化了表达式,发现没有多少字符可以工作。像这样的简单命令不起作用:

az storage entity insert --table-name table --account-name $StorageAccountName --if-exists replace --connection-string $StorageConnectionString --entity PartitionKey=ABC RowKey=DEF Field="(abc)" Field@odata.type=Edm.String

这会导致另一个错误“Field@odata.type 在这个时候是意外的。”

还有 |字符会导致问题,例如:

az storage entity insert --table-name table --account-name $StorageAccountName --if-exists replace --connection-string $StorageConnectionString --entity PartitionKey=ABC RowKey=DEF Field="|abc" Field@odata.type=Edm.String

给出“'abc' 不是内部或外部命令、可运行程序或批处理文件。

这反而可以正常工作:

az storage entity insert --table-name table --account-name $StorageAccountName --if-exists replace --connection-string $StorageConnectionString --entity PartitionKey=ABC RowKey=DEF Field="abc" Field@odata.type=Edm.String

那么为什么这些特殊字符会破坏命令以及如何修复它?我需要正则表达式的这两个字符和其他一些不起作用的字符。

当我直接从 Powershell 运行以及在使用 Invoke-Expression 的脚本中运行时,都会发生这些错误

【问题讨论】:

标签: azure-powershell azure-cli


【解决方案1】:

我最初认为这与 PowerShell handles single quotation marks vs double quotation marks 的方式有关,但事实证明我只完成了一半。 Octopus Deploy lists several solutions 包括单引号:

'"(abc)"'

这里是你的原始命令,然后是你的命令,用双引号括起来的单引号(我现在因为未能提供帐户名而出错):

【讨论】:

    猜你喜欢
    • 2019-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-12
    • 1970-01-01
    • 2020-03-13
    • 2019-10-13
    • 2017-03-20
    相关资源
    最近更新 更多