What is the PowerShell equivalent to this Bash command?

雨燕双飞 提交于 2019-11-29 14:09:53

问题


I'm trying to create a CLI command to have TFS check out all files that have a particular string in them. I primarily use Cygwin, but the tf command has trouble resolving the path when run within the Cygwin environment.

I figure PowerShell should be able to do the same thing, but I'm not sure what the equivalent commands to grep and xargs are.

So, what would be the equivalent PowerShell version to the following Bash command?

grep -l -r 'SomeSearchString' . | xargs -L1 tf edit

回答1:


Using some UNIX aliases in PowerShell (like ls):

ls -r | select-string 'SomeSearchString' | Foreach {tf edit $_.Path}

or in a more canonical Powershell form:

Get-ChildItem -Recurse | Select-String 'SomeSearchString' | 
    Foreach {tf edit $_.Path}

and using PowerShell aliases:

gci -r | sls 'SomeSearchString' | %{tf edit $_.Path}



回答2:


I find it easier to grok using a variable, e.g.,

PS> $files = Get-ChildItem -Recurse | 
       Select-String 'SomeSearchString' | 
       %{$_.path}  | 
       Select -Unique
PS> tf edit $files


来源:https://stackoverflow.com/questions/2102852/what-is-the-powershell-equivalent-to-this-bash-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!