2015-08-28 66 views
0

bash我写
echo prefix{t1,t2,t3}suffix
并得到了
prefixt1suffix prefixt2suffix prefixt3suffix展开列表在PowerShell中

是这样出现在PowerShell的? 列表expantion我的意思是。

+0

正在使用循环选项? – arco444

+0

'“t1”,“t2”,“t3”| %{“prefix”+ $ _}' –

+0

也许你可以使用'splatting'http://stackoverflow.com/questions/448911/how-to-expand-a-powershell-array-when-passing-it-to- a功能 –

回答

1

没有自动扩展,但你可以ForEach-Object cmdlet或阵列的ForEach方法PS 4 and higher轻松地做到这一点:

't1', 't2', 't3' | ForEach-Object {'prefix' + $_ + 'suffix'} 

@('t1', 't2', 't3').ForEach({'prefix' + $_ + 'suffix'}) 
+0

这不是一个解决方案,但很好。谢谢。 – OlegG

+0

@OlegG我很好奇,你有什么具体的原因,需要列表扩展是完全一样的bash?因为我相信内部bash也会循环播放,所以没有其他办法可以做到。 PowerShell没有这个特定的快捷方式,就是这样。 – beatcracker

+0

只需比较Bash命令行'vim -d/some/directory/file {1,2} .ps1'与我在PowerShell中编写的内容,即可看到我的理由。 – OlegG

1

几个其他的方法是:

't1', 't2', 't3' | % {"prefix$($_)suffix"} 

't1', 't2', 't3' | % {'prefix{0}suffix' -f $_} 
+0

这不是一个解决方案,但也很好。谢谢。 – OlegG