PowerShell,帮助函数的语法 [英] PowerShell, the syntax of help-function

查看:32
本文介绍了PowerShell,帮助函数的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

探索 helpget-help 之间的区别我做到了:

Exploring the difference between help and get-help I did:

  1. cd 函数:
  2. 获取内容帮助
  3. 所有输入参数的定义如下:[string]${Name}

$=初始化一个变量,{}一个哈希表??

$=initiate a variable, {} a hashtable??

感谢您的帮助.

推荐答案

有关官方文档,请参阅概念性about_Variables 帮助主题(使用 help about_Variables 调用它),特别是它的 "包含特殊字符的变量名称" 部分.

For the official documentation, see the conceptual about_Variables help topic (invoke it with help about_Variables), and in particular its "Variable Names that Include Special Characters" section.

{...} 中包含变量的名称 - 例如${foo} - 明确分隔变量名 (foo).

Enclosing the name of a variable in {...} - e.g. ${foo} - unambiguously delimits the variable name (foo).

虽然您可以将此表示法用于任何变量引用,但在以下情况下必须这样做:

While you can use this notation with any variable reference, doing so is required in the following scenarios:

  • 如果 名称包含异常字符,例如 -.(请参阅链接的帮助主题以获取准确的允许的字符);例如:

  • If the name contains unusual characters, such as - or . (see the linked help topic for the exact set of permissible characters); e.g.:

  • ${foo-bar}
  • ${foo.bar}

如果变量引用嵌入可扩展字符串("..."),如果紧随其后的字符会被解释为变量名的一部分,则您可能需要告诉 PowerShell 变量名的结束位置;例如:

If the variable reference is embedded in an expandable string ("..."), you may need to tell PowerShell where the variable name ends, if the immediately following characters would otherwise be interpreted as part of the variable name; e.g.:

  • "${foo}: bar" - 如果没有 {...},PowerShell 会解释 $foo:作为(不完整的)变量名称,失败,因为 foo 然后在 命名空间变量符号.

  • "${foo}: bar" - without the {...}, PowerShell would interpret $foo: as an (incomplete) variable name, which fails, because foo is then interpreted as the name of a PS drive in the context of namespace variable notation.

  • 注意:在这种情况下,另一种方法是 `-转义 : 字符:"$foo`: bar"
  • Note: An alternative in this case is to `-escape the : character: "$foo`: bar"

"A ${foo}l and his money ..." - 如果没有 {...},PowerShell 会寻找变量 $fool 代替.

"A ${foo}l and his money ..." - without the {...}, PowerShell would look for variable $fool instead.

虽然在您的示例中 (${Name}) 包含在 {...} 中是不是必要的,原因是使用的是代码是自动生成作为代理函数的,它包装了Get-Help cmdlet,这种生成机制有条不紊地将所有变量封装在 {...} 中.

While in your example (${Name}) enclosing in {...} is not necessary, the reason that it is used is that the code was automatically generated as a proxy function that wraps the Get-Help cmdlet, and this generation mechanism methodically encloses all variables in {...}.

这篇关于PowerShell,帮助函数的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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