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
)
?
@MikeZ's answer is quite correct in explaining the example in the question, but as far as addressing the question title, there is actually more to say! The
${}
notation actually has two uses; the second one is a hidden gem of PowerShell:That is, you can use this bracket notation to do file I/O operations if you provide a drive-qualified path, as defined in the MSDN page Provider Paths.
(The above image comes from the Complete Guide to PowerShell Punctuation, a one-page wallchart freely available for download, attached to my recent article at Simple-Talk.com.)
They are equivalent. It's just an alternative way of declaring a variable.
If you have characters that are illegal in a normal variable, you'd use the braces (think of it as "escaping" the variablename).
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:
From about_Variables
There is one additional usage.
One may have variable names like var1, var2, var11, var12, var101, etc. Regardless if this is desirable variable naming, it just may be.
Using brackets one can precisely determine what is to be used: assignment of
$var11
may be ambiguous, using${var1}1
or${var11}
leaves no room for mistakes.