我正在尝试创建一个CLI命令来让TFS检查所有包含特定字符串的文件。我主要使用Cygwin,但该tf
命令在 Cygwin 环境中运行时无法解析路径。
我认为 PowerShell 应该能够做同样的事情,但我不确定grep和xargs的等效命令是什么。
那么,与以下Bash命令等效的 PowerShell 版本是什么?
grep -l -r 'SomeSearchString' . | xargs -L1 tf edit
在 PowerShell 中使用一些 UNIX 别名(如 ls):
ls -r | select-string 'SomeSearchString' | Foreach {tf edit $_.Path}
或者以更规范的 Powershell 形式:
Get-ChildItem -Recurse | Select-String 'SomeSearchString' |
Foreach {tf edit $_.Path}
并使用 PowerShell 别名:
gci -r | sls 'SomeSearchString' | %{tf edit $_.Path}
我发现使用变量更容易理解,例如,
PS> $files = Get-ChildItem -Recurse |
Select-String 'SomeSearchString' |
%{$_.path} |
Select -Unique
PS> tf edit $files