gpt4 book ai didi

powershell - 与此 Bash 命令等效的 PowerShell 是什么?

转载 作者:行者123 更新时间:2023-12-02 23:17:37 25 4
gpt4 key购买 nike

我正在尝试创建一个 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}

关于powershell - 与此 Bash 命令等效的 PowerShell 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2102852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com