【问题标题】:PowerShell param is an empty string when it's notPowerShell 参数不是空字符串时
【发布时间】:2017-02-09 11:36:38
【问题描述】:

我正在尝试在文件中搜索 NodeJS 参数中给出的字符串。

param(
    [switch]$raw,
    [string]$input
)

[string]$file = "*.log"
if($raw) { $file = ".\raws\*.log" }

Get-ChildItem -Recurse -Include $file | select-string $input

问题是我收到$input 为空的错误:

我做错了什么?

【问题讨论】:

标签: powershell


【解决方案1】:

感谢@TessellatingHeckler 指出$input 是保留/自动变量,因此不能这样使用。

【讨论】:

  • 天哪,真是个救命稻草。我会注意到 $profileName 也是一个保留/自动变量,我遇到了同样的问题。
  • 对于任何偶然发现此线程的人,here 是 Powershell 中的自动变量列表
猜你喜欢
  • 1970-01-01
  • 2017-05-28
  • 2020-04-19
  • 1970-01-01
  • 1970-01-01
  • 2021-09-17
  • 1970-01-01
  • 2017-12-30
  • 1970-01-01
相关资源
最近更新 更多