首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >"(gl -stack)“和"gl -stack”的区别

"(gl -stack)“和"gl -stack”的区别
EN

Stack Overflow用户
提问于 2014-04-16 19:59:38
回答 1查看 136关注 0票数 4

我只是想知道为什么在圆括号(例如gl -stack )之间嵌入表达式时,我会得到两个不同的成员列表。似乎没有括号,表达式将被完全计算,结果立即传递给下一个管道组件。但是,使用括号,集合中的单个对象将一个接一个地传递,以便为集合中的对象而不是集合本身调用Get-Member。有关与PowerShell的示例,请参见下面的Get-Location -Stack交互。

提前感谢!

代码语言:javascript
运行
复制
PS C:\temp\loc1> pushd
PS C:\temp\loc1> pushd ..\loc2
PS C:\temp\loc2> gl -stack

Path
----
C:\temp\loc1
C:\temp\loc1


PS C:\temp\loc2> gl -stack | gm


   TypeName: System.Management.Automation.PathInfoStack

Name          MemberType Definition
----          ---------- ----------
Clear         Method     System.Void Clear()
Contains      Method     bool Contains(System.Management.Automation.PathInfo...
CopyTo        Method     System.Void CopyTo(System.Management.Automation.Pat...
Equals        Method     bool Equals(System.Object obj)
GetEnumerator Method     System.Collections.Generic.Stack`1+Enumerator[[Syst...
GetHashCode   Method     int GetHashCode()
GetType       Method     type GetType()
Peek          Method     System.Management.Automation.PathInfo Peek()
Pop           Method     System.Management.Automation.PathInfo Pop()
Push          Method     System.Void Push(System.Management.Automation.PathI...
ToArray       Method     System.Management.Automation.PathInfo[] ToArray()
ToString      Method     string ToString()
TrimExcess    Method     System.Void TrimExcess()
Count         Property   System.Int32 Count {get;}
Name          Property   System.String Name {get;}


PS C:\temp\loc2> (gl -stack) | gm


   TypeName: System.Management.Automation.PathInfo

Name         MemberType Definition
----         ---------- ----------
Equals       Method     bool Equals(System.Object obj)
GetHashCode  Method     int GetHashCode()
GetType      Method     type GetType()
ToString     Method     string ToString()
Drive        Property   System.Management.Automation.PSDriveInfo Drive {get;}
Path         Property   System.String Path {get;}
Provider     Property   System.Management.Automation.ProviderInfo Provider {...
ProviderPath Property   System.String ProviderPath {get;}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-16 22:33:00

正如您所看到的,Get-Location -Stack返回一个PathInfoStack对象。该对象是从实现Stack<T>的ICollection派生的。当您将表达式放入()中时,PowerShell计算该表达式。如果结果是一个集合,那么它将被迭代并输出。您可以在这个简单的函数中看到同样的内容:

代码语言:javascript
运行
复制
PS> function GetArray() { ,@(1,2,3) }
PS> GetArray | Foreach {$_.GetType().FullName}
System.Object[]
PS> (GetArray) | Foreach {$_.GetType().FullName}
System.Int32
System.Int32
System.Int32
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23119007

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档