什么是 PowerShell 中的可扩展字符串

What is an expandable string in PowerShell

在 PowerShell 的 documentation 中,我遇到了表达式 expandable string:

Argument mode is designed for parsing arguments and parameters for commands in a shell environment. All input is treated as an expandable string unless it uses one of the following syntaxes:

不幸的是,我找不到 可扩展字符串 的定义,我的问题是:PowerShell 中的 可扩展字符串 是什么?

很遗憾,在撰写本文时,有关 PowerShell 字符串文字的官方帮助主题 about_Quoting_Rules doesn't introduce the term expandable string [update: the online version now does; to also see the update locally, you may have to run Update-Help]。

一个可扩展字符串是:

  • A double-quoted string literal ("...")

    • 相比之下,引号字符串('...')是逐字(文字)字符串。
    • 有关所有类型的 PowerShell 字符串文字的概述,其中包括 here-string 变体(例如,@"<newline>...<newline>"@),请参阅 [=23] 的底部=].
  • 双引号字符串执行字符串插值(展开).

    • 这允许您按原样嵌入简单的变量引用(例如,"$var"),并通过 $()(例如,"$($var.property)")嵌入表达式和整个语句。逐字转义 $(和 ")字符。 `。将变量名称括在 {...} 中以消除歧义(例如 "${var}")。
    • 有关完整规则,请参阅 this answer