问题描述
我有一个脚本,其中函数参数的表达方式如下:
I have a script where function parameters are expressed like this:
param(
${param1},
${param2},
${param3}
)
什么意思?我一直找不到这方面的文档.
What does it mean? I have been unable to find documentation on this.
以这种方式而不是更常见的方式编写参数有什么意义
What's the point of writing parameters that way instead of the more usual
param(
$param1,
$param2,
$param3
)
?
推荐答案
它们都只是参数声明.这两个片段是等效的.此处可以使用任何一种语法,但是花括号形式允许在变量名称中不合法的字符.来自 PowerShell 3.0 语言规范:
They are both just parameter declarations. The two snippets are equivalent. Either syntax can be used here, however the braced form allows characters that would not otherwise be legal in variable names. From the PowerShell 3.0 language specification:
变量名有两种书写方式:括号变量名,以 $ 开头,后跟以大括号分隔的一组或多个几乎任意的字符;和一个普通变量名,它也以 $ 开头,后跟一组一个或多个字符的集合,这些字符来自比花括号变量名允许的更严格的集合.每个普通的变量名都可以用一个对应的花括号变量名来表示.
要创建或显示包含空格或特殊字符的变量名称,请将变量名称括在大括号中.这会指示 Windows PowerShell 按字面意思解释变量名称中的字符.
例如,以下命令创建并显示一个名为save-items"的变量.
For example, the following command creates and then displays a variable named "save-items".
C:\PS> ${save-items} = "a", "b", "c"
C:\PS> ${save-items}
a
b
c
这篇关于PowerShell中${}的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!