在下面的代码中,有没有办法从第三段引用第二段中的当前对象?

`$a = "one", "two", "three"`
`$a | % {$_ -replace "t","x" } | % { $_ }`

稍微解释一下,我希望能够在第三个管道段中使用类似 | % { "$_.$_ : $_" } 的东西来获得这个输出:
one: one
two: xwo
three: xhree

最佳答案

这是我目前找到的唯一解决方案。有没有更好的选择?

$a = "one", "two", "three"
$a | % { $i = $_; $_ -replace "t","x" } | % { "$i : $_" }

输出:
one : one
two : xwo
three : xhree

关于powershell - 有没有办法引用管道中的前一个对象?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14566660/

10-13 07:49