什么是PowerShell中的可扩展字符串 [英] What is an expandable string in PowerShell

查看:57
本文介绍了什么是PowerShell中的可扩展字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PowerShell的文档,我遇到了表达式可扩展字符串:

In PowerShell's documentation, I have come across the expression expandable string:

参数模式设计用于解析Shell环境中命令的参数和参数.除非所有输入使用以下语法之一,否则它将被视为可扩展字符串:

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

Unfortunately, I am unable to find a definition for expandable string and my question is: what is an expandable string in PowerShell?

推荐答案

很遗憾,在撰写本文时,有关PowerShell字符串文字的官方帮助主题此GitHub文档PR ;在线版本将自动反映更改,但是要在本地也查看更改,您必须运行 更新帮助 .

It is definitely unfortunate that, as of this writing, the official help topic on PowerShell string literals, about_Quoting_Rules doesn't introduce the term expandable string; however, this will change soon: see this GitHub docs PR; the online version will reflect the changes automatically, but to see them locally as well, you'll have to run Update-Help.

可扩展字符串 为:

  • 带有 double 且带引号的字符串 literal ("..." )

  • 相比之下,用 引号的字符串('...')是 verbatim (文字)字符串;有关所有类型的PowerShell字符串文字的概述,其中包括 here-string 变体(例如, @"< newline> ...< newline>"@@ ),请参见此答案的底部.
  • By contrast, a single-quoted string ('...') is a verbatim (literal) string; for an overview of all types of PowerShell string literals, which includes here-string variants (e.g., @"<newline>...<newline>"@), see the bottom section of this answer.

双引号字符串执行 字符串内插(扩展).

Double-quoted strings perform string interpolation (expansion).

  • 这使您可以按原样嵌入简单的变量引用(例如,"$ var" ),并通过 $()嵌入表达式和整个语句(例如,"$($ var.property)" ).转义 verbatim $ (和" )字符.与`.将变量名称括在 {...} 中以消除歧义(例如,"$$ var}" ).有关完整的规则,请参见此答案.
  • This allows you to embed simple variable references as-is (e.g, "$var"), and expressions and whole statements via $() (e.g., "$($var.property)"). Escape verbatim $ (and ") chars. with `. Enclose variable names in {...} for disambiguation (e.g. "${var}"). For the complete rules, see this answer.

这篇关于什么是PowerShell中的可扩展字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆