开发者

Powershell: Using substring in pipeline

开发者 https://www.devze.com 2023-01-24 18:02 出处:网络
is there a possibility to manipulate the items in a pipeline of powe开发者_运维技巧rshell? In more concrete words: I start my pipeline with an \"svn list\". This returns me a list of paths in my repos

is there a possibility to manipulate the items in a pipeline of powe开发者_运维技巧rshell? In more concrete words: I start my pipeline with an "svn list". This returns me a list of paths in my repository, all directories with a trailing "/". The list of paths should be stored in an array, but without the "/". This:

svn list svn://server/repository/myPath | $_.TrimEnd("/")

does not work because TrimEnd is an expression and may not be used within a pipeline. The result of the pipeline should be something like

$a = @("foo", "bar)

Thanks in advance for your answers.


I dont have the SVN stuff to try the same here. But, from what I see, you are missing a Foreach-Object after the pipe

Try this

svn list svn://server/repository/myPath | ForEach-object { $_.TrimEnd("/") }

or

svn list svn://server/repository/myPath | % { $_.TrimEnd("/") }


svn list svn://server/repository/myPath | % TrimEnd /
0

精彩评论

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