开发者

What is the Powershell analogue of $@ used to call another command?

In a Unix shell script, to call command foo 开发者_Python百科on the original arguments to the script, you just write

foo $@

In Powershell, $args is an array of (typically) strings holding the current script's arguments. If you write

foo $args

will the same thing happen as in bash or other typical Unix shell script interpreters?


You want to use argument splatting which is new in PowerShell 2.0. The variable used for splatting can be either an array (args are bound positionally) or a hashtable (keys map to parameter names and their values provide the argument). If you don't declare any parameters then use @args. The problem with attempting to use $args is that it will be sent as an array to the first parmeter rather than splatted across all the parametets. However many folks do declare parameter. In this case you want to use @PSBoundParameters e.g.:

foo @PSBoundParameters
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜